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>
|
||||||
@@ -13,6 +13,7 @@
|
|||||||
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
<PackageLicenseExpression>MIT</PackageLicenseExpression>
|
||||||
<OutputType>Library</OutputType>
|
<OutputType>Library</OutputType>
|
||||||
<IsPackable>false</IsPackable>
|
<IsPackable>false</IsPackable>
|
||||||
|
<IsTestProject>true</IsTestProject>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -964,6 +964,9 @@ namespace DynamORM.Builders.Implementation
|
|||||||
/// freeing, releasing, or resetting unmanaged resources.</summary>
|
/// freeing, releasing, or resetting unmanaged resources.</summary>
|
||||||
public virtual void Dispose()
|
public virtual void Dispose()
|
||||||
{
|
{
|
||||||
|
if (IsDisposed)
|
||||||
|
return;
|
||||||
|
|
||||||
IsDisposed = true;
|
IsDisposed = true;
|
||||||
|
|
||||||
if (Database != null)
|
if (Database != null)
|
||||||
|
|||||||
@@ -32,6 +32,7 @@ namespace DynamORM
|
|||||||
|
|
||||||
private List<Data> _data = new List<Data>();
|
private List<Data> _data = new List<Data>();
|
||||||
private int _currentDataPosition = 0;
|
private int _currentDataPosition = 0;
|
||||||
|
private bool _isDisposed;
|
||||||
|
|
||||||
private DynamicCachedReader()
|
private DynamicCachedReader()
|
||||||
{
|
{
|
||||||
@@ -445,11 +446,27 @@ namespace DynamORM
|
|||||||
/// freeing, releasing, or resetting unmanaged resources.</summary>
|
/// freeing, releasing, or resetting unmanaged resources.</summary>
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
if (_isDisposed)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_isDisposed = true;
|
||||||
|
IsClosed = true;
|
||||||
|
|
||||||
|
if (_data == null)
|
||||||
|
return;
|
||||||
|
|
||||||
foreach (var data in _data)
|
foreach (var data in _data)
|
||||||
{
|
{
|
||||||
|
if (data == null)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (data._names != null)
|
||||||
data._names.Clear();
|
data._names.Clear();
|
||||||
|
if (data._types != null)
|
||||||
data._types.Clear();
|
data._types.Clear();
|
||||||
|
if (data._cache != null)
|
||||||
data._cache.Clear();
|
data._cache.Clear();
|
||||||
|
if (data._schema != null)
|
||||||
data._schema.Dispose();
|
data._schema.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -264,18 +264,31 @@ namespace DynamORM
|
|||||||
/// freeing, releasing, or resetting unmanaged resources.</summary>
|
/// freeing, releasing, or resetting unmanaged resources.</summary>
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
lock (_db.SyncLock)
|
if (IsDisposed)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var db = _db;
|
||||||
|
if (db == null)
|
||||||
{
|
{
|
||||||
|
IsDisposed = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
lock (db.SyncLock)
|
||||||
|
{
|
||||||
|
if (IsDisposed)
|
||||||
|
return;
|
||||||
|
|
||||||
|
IsDisposed = true;
|
||||||
|
|
||||||
if (_con != null)
|
if (_con != null)
|
||||||
{
|
{
|
||||||
List<IDbCommand> pool = _db.CommandsPool.TryGetValue(_con.Connection);
|
List<IDbCommand> pool = db.CommandsPool.TryGetValue(_con.Connection);
|
||||||
|
|
||||||
if (pool != null && pool.Contains(this))
|
if (pool != null && pool.Contains(this))
|
||||||
pool.Remove(this);
|
pool.Remove(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
IsDisposed = true;
|
|
||||||
|
|
||||||
if (_command != null)
|
if (_command != null)
|
||||||
{
|
{
|
||||||
_command.Parameters.Clear();
|
_command.Parameters.Clear();
|
||||||
@@ -283,6 +296,9 @@ namespace DynamORM
|
|||||||
_command.Dispose();
|
_command.Dispose();
|
||||||
_command = null;
|
_command = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_con = null;
|
||||||
|
_db = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -165,7 +165,15 @@ namespace DynamORM
|
|||||||
/// releasing, or resetting unmanaged resources.</summary>
|
/// releasing, or resetting unmanaged resources.</summary>
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
_db.Close(Connection);
|
if (IsDisposed)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var db = _db;
|
||||||
|
if (db != null && Connection != null)
|
||||||
|
db.Close(Connection);
|
||||||
|
|
||||||
|
Connection = null;
|
||||||
|
_db = null;
|
||||||
IsDisposed = true;
|
IsDisposed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2010,6 +2010,9 @@ namespace DynamORM
|
|||||||
/// releasing, or resetting unmanaged resources.</summary>
|
/// releasing, or resetting unmanaged resources.</summary>
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
if (IsDisposed)
|
||||||
|
return;
|
||||||
|
|
||||||
#if !DYNAMORM_OMMIT_OLDSYNTAX
|
#if !DYNAMORM_OMMIT_OLDSYNTAX
|
||||||
List<DynamicTable> tables = TablesCache.Values.ToList();
|
List<DynamicTable> tables = TablesCache.Values.ToList();
|
||||||
TablesCache.Clear();
|
TablesCache.Clear();
|
||||||
@@ -2067,6 +2070,8 @@ namespace DynamORM
|
|||||||
if (_proc != null)
|
if (_proc != null)
|
||||||
_proc.Dispose();
|
_proc.Dispose();
|
||||||
|
|
||||||
|
_proc = null;
|
||||||
|
_tempConn = null;
|
||||||
IsDisposed = true;
|
IsDisposed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -55,6 +55,7 @@ namespace DynamORM
|
|||||||
{
|
{
|
||||||
private DynamicDatabase _db;
|
private DynamicDatabase _db;
|
||||||
private List<string> _prefixes;
|
private List<string> _prefixes;
|
||||||
|
private bool _isDisposed;
|
||||||
|
|
||||||
internal DynamicProcedureInvoker(DynamicDatabase db, List<string> prefixes = null)
|
internal DynamicProcedureInvoker(DynamicDatabase db, List<string> prefixes = null)
|
||||||
{
|
{
|
||||||
@@ -450,6 +451,12 @@ namespace DynamORM
|
|||||||
/// freeing, releasing, or resetting unmanaged resources.</summary>
|
/// freeing, releasing, or resetting unmanaged resources.</summary>
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
if (_isDisposed)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_isDisposed = true;
|
||||||
|
_db = null;
|
||||||
|
_prefixes = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -954,6 +954,9 @@ namespace DynamORM
|
|||||||
/// freeing, releasing, or resetting unmanaged resources.</summary>
|
/// freeing, releasing, or resetting unmanaged resources.</summary>
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
if (IsDisposed)
|
||||||
|
return;
|
||||||
|
|
||||||
// Lose reference but don't kill it.
|
// Lose reference but don't kill it.
|
||||||
if (Database != null)
|
if (Database != null)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -174,11 +174,18 @@ namespace DynamORM
|
|||||||
/// freeing, releasing, or resetting unmanaged resources.</summary>
|
/// freeing, releasing, or resetting unmanaged resources.</summary>
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
if (_isDisposed)
|
||||||
|
return;
|
||||||
|
|
||||||
_isDisposed = true;
|
_isDisposed = true;
|
||||||
Rollback();
|
Rollback();
|
||||||
|
|
||||||
if (_disposed != null)
|
if (_disposed != null)
|
||||||
_disposed();
|
_disposed();
|
||||||
|
|
||||||
|
_disposed = null;
|
||||||
|
_con = null;
|
||||||
|
_db = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Gets a value indicating whether this instance is disposed.</summary>
|
/// <summary>Gets a value indicating whether this instance is disposed.</summary>
|
||||||
|
|||||||
@@ -1449,6 +1449,9 @@ namespace DynamORM.Helpers.Dynamics
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public void Dispose()
|
public void Dispose()
|
||||||
{
|
{
|
||||||
|
if (IsDisposed)
|
||||||
|
return;
|
||||||
|
|
||||||
IsDisposed = true;
|
IsDisposed = true;
|
||||||
|
|
||||||
if (_uncertainResult != null)
|
if (_uncertainResult != null)
|
||||||
|
|||||||
@@ -127,11 +127,14 @@ namespace DynamORM.Mapper
|
|||||||
return null;
|
return null;
|
||||||
|
|
||||||
var objParm = Expression.Parameter(typeof(object), "o");
|
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>>(
|
return Expression.Lambda<Func<object, object>>(
|
||||||
Expression.Convert(
|
Expression.Convert(
|
||||||
Expression.Property(
|
Expression.Property(
|
||||||
Expression.TypeAs(objParm, property.DeclaringType),
|
target,
|
||||||
property.Name),
|
property.Name),
|
||||||
typeof(object)), objParm).Compile();
|
typeof(object)), objParm).Compile();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user