Merge branch 'fix/disposal-guards'
This commit is contained in:
File diff suppressed because it is too large
Load Diff
29
DynamORM.Net40.csproj
Normal file
29
DynamORM.Net40.csproj
Normal file
@@ -0,0 +1,29 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net40</TargetFramework>
|
||||
<Description>Dynamic Object-Relational Mapping library (amalgamated for .NET 4.0).</Description>
|
||||
<Copyright>Copyright © RUSSEK Software 2012-2026</Copyright>
|
||||
<Company>RUSSEK Software</Company>
|
||||
<Authors>Grzegorz Russek</Authors>
|
||||
<VersionPrefix>1.9</VersionPrefix>
|
||||
<Product>DynamORM</Product>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
|
||||
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'net40'">
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="$(TargetFramework.StartsWith('net4')) AND '$(MSBuildRuntimeType)' == 'Core' AND '$(OS)' != 'Windows_NT'">
|
||||
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="All" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Include="AmalgamationTool/DynamORM.Amalgamation.cs" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
@@ -1,8 +1,8 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Description>Dynamic Object-Relational Mapping tests library.</Description>
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<Description>Dynamic Object-Relational Mapping tests library.</Description>
|
||||
<Copyright>Copyright © RUSSEK Software 2012-2026</Copyright>
|
||||
<Company>RUSSEK Software</Company>
|
||||
<Authors>Grzegorz Russek</Authors>
|
||||
@@ -11,10 +11,11 @@
|
||||
<PackageProjectUrl>https://dr4cul4.pl</PackageProjectUrl>
|
||||
<Product>DynamORM</Product>
|
||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||
<OutputType>Library</OutputType>
|
||||
<IsPackable>false</IsPackable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
<OutputType>Library</OutputType>
|
||||
<IsPackable>false</IsPackable>
|
||||
<IsTestProject>true</IsTestProject>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Condition="$(TargetFramework.StartsWith('net4')) AND '$(MSBuildRuntimeType)' == 'Core' AND '$(OS)' != 'Windows_NT'">
|
||||
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="1.0.3" PrivateAssets="All" />
|
||||
@@ -41,4 +42,4 @@
|
||||
<None Remove="Helpers\**" />
|
||||
<None Remove="Modify\**" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
</Project>
|
||||
|
||||
@@ -960,14 +960,17 @@ namespace DynamORM.Builders.Implementation
|
||||
/// <summary>Gets a value indicating whether this instance is disposed.</summary>
|
||||
public bool IsDisposed { get; private set; }
|
||||
|
||||
/// <summary>Performs application-defined tasks associated with
|
||||
/// freeing, releasing, or resetting unmanaged resources.</summary>
|
||||
public virtual void Dispose()
|
||||
{
|
||||
IsDisposed = true;
|
||||
|
||||
if (Database != null)
|
||||
Database.RemoveFromCache(this);
|
||||
/// <summary>Performs application-defined tasks associated with
|
||||
/// freeing, releasing, or resetting unmanaged resources.</summary>
|
||||
public virtual void Dispose()
|
||||
{
|
||||
if (IsDisposed)
|
||||
return;
|
||||
|
||||
IsDisposed = true;
|
||||
|
||||
if (Database != null)
|
||||
Database.RemoveFromCache(this);
|
||||
|
||||
if (Parameters != null)
|
||||
{
|
||||
@@ -994,4 +997,4 @@ namespace DynamORM.Builders.Implementation
|
||||
|
||||
#endregion IExtendedDisposable
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,8 +30,9 @@ namespace DynamORM
|
||||
internal IList<object> _cache;
|
||||
}
|
||||
|
||||
private List<Data> _data = new List<Data>();
|
||||
private int _currentDataPosition = 0;
|
||||
private List<Data> _data = new List<Data>();
|
||||
private int _currentDataPosition = 0;
|
||||
private bool _isDisposed;
|
||||
|
||||
private DynamicCachedReader()
|
||||
{
|
||||
@@ -443,18 +444,34 @@ namespace DynamORM
|
||||
|
||||
/// <summary>Performs application-defined tasks associated with
|
||||
/// freeing, releasing, or resetting unmanaged resources.</summary>
|
||||
public void Dispose()
|
||||
{
|
||||
foreach (var data in _data)
|
||||
{
|
||||
data._names.Clear();
|
||||
data._types.Clear();
|
||||
data._cache.Clear();
|
||||
data._schema.Dispose();
|
||||
}
|
||||
|
||||
_data.Clear();
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
if (_isDisposed)
|
||||
return;
|
||||
|
||||
_isDisposed = true;
|
||||
IsClosed = true;
|
||||
|
||||
if (_data == null)
|
||||
return;
|
||||
|
||||
foreach (var data in _data)
|
||||
{
|
||||
if (data == null)
|
||||
continue;
|
||||
|
||||
if (data._names != null)
|
||||
data._names.Clear();
|
||||
if (data._types != null)
|
||||
data._types.Clear();
|
||||
if (data._cache != null)
|
||||
data._cache.Clear();
|
||||
if (data._schema != null)
|
||||
data._schema.Dispose();
|
||||
}
|
||||
|
||||
_data.Clear();
|
||||
}
|
||||
|
||||
#endregion IDisposable Members
|
||||
|
||||
@@ -721,4 +738,4 @@ namespace DynamORM
|
||||
|
||||
#endregion IDataRecord Members
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,35 +260,51 @@ namespace DynamORM
|
||||
|
||||
#region IExtendedDisposable Members
|
||||
|
||||
/// <summary>Performs application-defined tasks associated with
|
||||
/// freeing, releasing, or resetting unmanaged resources.</summary>
|
||||
public void Dispose()
|
||||
{
|
||||
lock (_db.SyncLock)
|
||||
{
|
||||
if (_con != null)
|
||||
{
|
||||
List<IDbCommand> pool = _db.CommandsPool.TryGetValue(_con.Connection);
|
||||
|
||||
if (pool != null && pool.Contains(this))
|
||||
pool.Remove(this);
|
||||
}
|
||||
|
||||
IsDisposed = true;
|
||||
|
||||
if (_command != null)
|
||||
{
|
||||
_command.Parameters.Clear();
|
||||
|
||||
_command.Dispose();
|
||||
_command = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>Performs application-defined tasks associated with
|
||||
/// freeing, releasing, or resetting unmanaged resources.</summary>
|
||||
public void Dispose()
|
||||
{
|
||||
if (IsDisposed)
|
||||
return;
|
||||
|
||||
var db = _db;
|
||||
if (db == null)
|
||||
{
|
||||
IsDisposed = true;
|
||||
return;
|
||||
}
|
||||
|
||||
lock (db.SyncLock)
|
||||
{
|
||||
if (IsDisposed)
|
||||
return;
|
||||
|
||||
IsDisposed = true;
|
||||
|
||||
if (_con != null)
|
||||
{
|
||||
List<IDbCommand> pool = db.CommandsPool.TryGetValue(_con.Connection);
|
||||
|
||||
if (pool != null && pool.Contains(this))
|
||||
pool.Remove(this);
|
||||
}
|
||||
|
||||
if (_command != null)
|
||||
{
|
||||
_command.Parameters.Clear();
|
||||
|
||||
_command.Dispose();
|
||||
_command = null;
|
||||
}
|
||||
|
||||
_con = null;
|
||||
_db = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Gets a value indicating whether this instance is disposed.</summary>
|
||||
public bool IsDisposed { get; private set; }
|
||||
|
||||
#endregion IExtendedDisposable Members
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,17 +161,25 @@ namespace DynamORM
|
||||
|
||||
#region IExtendedDisposable Members
|
||||
|
||||
/// <summary>Performs application-defined tasks associated with freeing,
|
||||
/// releasing, or resetting unmanaged resources.</summary>
|
||||
public void Dispose()
|
||||
{
|
||||
_db.Close(Connection);
|
||||
IsDisposed = true;
|
||||
}
|
||||
/// <summary>Performs application-defined tasks associated with freeing,
|
||||
/// releasing, or resetting unmanaged resources.</summary>
|
||||
public void Dispose()
|
||||
{
|
||||
if (IsDisposed)
|
||||
return;
|
||||
|
||||
var db = _db;
|
||||
if (db != null && Connection != null)
|
||||
db.Close(Connection);
|
||||
|
||||
Connection = null;
|
||||
_db = null;
|
||||
IsDisposed = true;
|
||||
}
|
||||
|
||||
/// <summary>Gets a value indicating whether this instance is disposed.</summary>
|
||||
public bool IsDisposed { get; private set; }
|
||||
|
||||
#endregion IExtendedDisposable Members
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2006,13 +2006,16 @@ namespace DynamORM
|
||||
|
||||
#region IExtendedDisposable Members
|
||||
|
||||
/// <summary>Performs application-defined tasks associated with freeing,
|
||||
/// releasing, or resetting unmanaged resources.</summary>
|
||||
public void Dispose()
|
||||
{
|
||||
#if !DYNAMORM_OMMIT_OLDSYNTAX
|
||||
List<DynamicTable> tables = TablesCache.Values.ToList();
|
||||
TablesCache.Clear();
|
||||
/// <summary>Performs application-defined tasks associated with freeing,
|
||||
/// releasing, or resetting unmanaged resources.</summary>
|
||||
public void Dispose()
|
||||
{
|
||||
if (IsDisposed)
|
||||
return;
|
||||
|
||||
#if !DYNAMORM_OMMIT_OLDSYNTAX
|
||||
List<DynamicTable> tables = TablesCache.Values.ToList();
|
||||
TablesCache.Clear();
|
||||
|
||||
tables.ForEach(t => t.Dispose());
|
||||
tables.Clear();
|
||||
@@ -2063,16 +2066,18 @@ namespace DynamORM
|
||||
RemainingBuilders = null;
|
||||
}
|
||||
|
||||
ClearSchema();
|
||||
if (_proc != null)
|
||||
_proc.Dispose();
|
||||
|
||||
IsDisposed = true;
|
||||
}
|
||||
ClearSchema();
|
||||
if (_proc != null)
|
||||
_proc.Dispose();
|
||||
|
||||
_proc = null;
|
||||
_tempConn = null;
|
||||
IsDisposed = true;
|
||||
}
|
||||
|
||||
/// <summary>Gets a value indicating whether this instance is disposed.</summary>
|
||||
public bool IsDisposed { get; private set; }
|
||||
|
||||
#endregion IExtendedDisposable Members
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,10 +51,11 @@ namespace DynamORM
|
||||
/// public class ProcResult { [Column("outp")] public Guid Output { get; set; } }
|
||||
/// ProcResult res4 = db.Procedures.sp_Test_Scalar_In_Out<ProcResult>(inp: Guid.NewGuid(), out_outp: Guid.Empty) as ProcResult;
|
||||
/// </code>As you can se, you can use mapper to do job for you.</example>
|
||||
public class DynamicProcedureInvoker : DynamicObject, IDisposable
|
||||
{
|
||||
private DynamicDatabase _db;
|
||||
private List<string> _prefixes;
|
||||
public class DynamicProcedureInvoker : DynamicObject, IDisposable
|
||||
{
|
||||
private DynamicDatabase _db;
|
||||
private List<string> _prefixes;
|
||||
private bool _isDisposed;
|
||||
|
||||
internal DynamicProcedureInvoker(DynamicDatabase db, List<string> prefixes = null)
|
||||
{
|
||||
@@ -446,10 +447,16 @@ namespace DynamORM
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>Performs application-defined tasks associated with
|
||||
/// freeing, releasing, or resetting unmanaged resources.</summary>
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>Performs application-defined tasks associated with
|
||||
/// freeing, releasing, or resetting unmanaged resources.</summary>
|
||||
public void Dispose()
|
||||
{
|
||||
if (_isDisposed)
|
||||
return;
|
||||
|
||||
_isDisposed = true;
|
||||
_db = null;
|
||||
_prefixes = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -950,15 +950,18 @@ namespace DynamORM
|
||||
|
||||
#region IExtendedDisposable Members
|
||||
|
||||
/// <summary>Performs application-defined tasks associated with
|
||||
/// freeing, releasing, or resetting unmanaged resources.</summary>
|
||||
public void Dispose()
|
||||
{
|
||||
// Lose reference but don't kill it.
|
||||
if (Database != null)
|
||||
{
|
||||
Database.RemoveFromCache(this);
|
||||
Database = null;
|
||||
/// <summary>Performs application-defined tasks associated with
|
||||
/// freeing, releasing, or resetting unmanaged resources.</summary>
|
||||
public void Dispose()
|
||||
{
|
||||
if (IsDisposed)
|
||||
return;
|
||||
|
||||
// Lose reference but don't kill it.
|
||||
if (Database != null)
|
||||
{
|
||||
Database.RemoveFromCache(this);
|
||||
Database = null;
|
||||
}
|
||||
|
||||
IsDisposed = true;
|
||||
@@ -989,4 +992,4 @@ namespace DynamORM
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,20 +170,27 @@ namespace DynamORM
|
||||
|
||||
#region IExtendedDisposable Members
|
||||
|
||||
/// <summary>Performs application-defined tasks associated with
|
||||
/// freeing, releasing, or resetting unmanaged resources.</summary>
|
||||
public void Dispose()
|
||||
{
|
||||
_isDisposed = true;
|
||||
Rollback();
|
||||
|
||||
if (_disposed != null)
|
||||
_disposed();
|
||||
}
|
||||
/// <summary>Performs application-defined tasks associated with
|
||||
/// freeing, releasing, or resetting unmanaged resources.</summary>
|
||||
public void Dispose()
|
||||
{
|
||||
if (_isDisposed)
|
||||
return;
|
||||
|
||||
_isDisposed = true;
|
||||
Rollback();
|
||||
|
||||
if (_disposed != null)
|
||||
_disposed();
|
||||
|
||||
_disposed = null;
|
||||
_con = null;
|
||||
_db = null;
|
||||
}
|
||||
|
||||
/// <summary>Gets a value indicating whether this instance is disposed.</summary>
|
||||
public bool IsDisposed { get { return !_isOperational; } }
|
||||
|
||||
#endregion IExtendedDisposable Members
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1444,15 +1444,18 @@ namespace DynamORM.Helpers.Dynamics
|
||||
/// <summary>Gets a value indicating whether this instance is disposed.</summary>
|
||||
public bool IsDisposed { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
IsDisposed = true;
|
||||
|
||||
if (_uncertainResult != null)
|
||||
{
|
||||
/// <summary>
|
||||
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
if (IsDisposed)
|
||||
return;
|
||||
|
||||
IsDisposed = true;
|
||||
|
||||
if (_uncertainResult != null)
|
||||
{
|
||||
if (_uncertainResult is Node)
|
||||
((Node)_uncertainResult).Dispose();
|
||||
|
||||
@@ -1486,4 +1489,4 @@ namespace DynamORM.Helpers.Dynamics
|
||||
|
||||
#endregion Implementation of IExtendedDisposable
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,18 +123,21 @@ namespace DynamORM.Mapper
|
||||
|
||||
private Func<object, object> CreateGetter(PropertyInfo property)
|
||||
{
|
||||
if (property == null || !property.CanRead)
|
||||
return null;
|
||||
|
||||
var objParm = Expression.Parameter(typeof(object), "o");
|
||||
|
||||
return Expression.Lambda<Func<object, object>>(
|
||||
Expression.Convert(
|
||||
Expression.Property(
|
||||
Expression.TypeAs(objParm, property.DeclaringType),
|
||||
property.Name),
|
||||
typeof(object)), objParm).Compile();
|
||||
}
|
||||
if (property == null || !property.CanRead)
|
||||
return null;
|
||||
|
||||
var objParm = Expression.Parameter(typeof(object), "o");
|
||||
var target = property.DeclaringType.IsValueType
|
||||
? (Expression)Expression.Convert(objParm, property.DeclaringType)
|
||||
: Expression.TypeAs(objParm, property.DeclaringType);
|
||||
|
||||
return Expression.Lambda<Func<object, object>>(
|
||||
Expression.Convert(
|
||||
Expression.Property(
|
||||
target,
|
||||
property.Name),
|
||||
typeof(object)), objParm).Compile();
|
||||
}
|
||||
|
||||
private Action<object, object> CreateSetter(PropertyInfo property)
|
||||
{
|
||||
@@ -276,4 +279,4 @@ namespace DynamORM.Mapper
|
||||
|
||||
#endregion Type command cache
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user