Merge branch 'fix/disposal-guards'

This commit is contained in:
root
2026-02-26 07:46:22 +01:00
13 changed files with 15575 additions and 16018 deletions

File diff suppressed because it is too large Load Diff

29
DynamORM.Net40.csproj Normal file
View 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>

View File

@@ -13,6 +13,7 @@
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<OutputType>Library</OutputType>
<IsPackable>false</IsPackable>
<IsTestProject>true</IsTestProject>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

View File

@@ -964,6 +964,9 @@ namespace DynamORM.Builders.Implementation
/// freeing, releasing, or resetting unmanaged resources.</summary>
public virtual void Dispose()
{
if (IsDisposed)
return;
IsDisposed = true;
if (Database != null)

View File

@@ -32,6 +32,7 @@ namespace DynamORM
private List<Data> _data = new List<Data>();
private int _currentDataPosition = 0;
private bool _isDisposed;
private DynamicCachedReader()
{
@@ -445,11 +446,27 @@ namespace DynamORM
/// freeing, releasing, or resetting unmanaged resources.</summary>
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();
}

View File

@@ -264,18 +264,31 @@ namespace DynamORM
/// freeing, releasing, or resetting unmanaged resources.</summary>
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)
{
List<IDbCommand> pool = _db.CommandsPool.TryGetValue(_con.Connection);
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();
@@ -283,6 +296,9 @@ namespace DynamORM
_command.Dispose();
_command = null;
}
_con = null;
_db = null;
}
}

View File

@@ -165,7 +165,15 @@ namespace DynamORM
/// releasing, or resetting unmanaged resources.</summary>
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;
}

View File

@@ -2010,6 +2010,9 @@ namespace DynamORM
/// releasing, or resetting unmanaged resources.</summary>
public void Dispose()
{
if (IsDisposed)
return;
#if !DYNAMORM_OMMIT_OLDSYNTAX
List<DynamicTable> tables = TablesCache.Values.ToList();
TablesCache.Clear();
@@ -2067,6 +2070,8 @@ namespace DynamORM
if (_proc != null)
_proc.Dispose();
_proc = null;
_tempConn = null;
IsDisposed = true;
}

View File

@@ -55,6 +55,7 @@ namespace DynamORM
{
private DynamicDatabase _db;
private List<string> _prefixes;
private bool _isDisposed;
internal DynamicProcedureInvoker(DynamicDatabase db, List<string> prefixes = null)
{
@@ -450,6 +451,12 @@ namespace DynamORM
/// freeing, releasing, or resetting unmanaged resources.</summary>
public void Dispose()
{
if (_isDisposed)
return;
_isDisposed = true;
_db = null;
_prefixes = null;
}
}
}

View File

@@ -954,6 +954,9 @@ namespace DynamORM
/// freeing, releasing, or resetting unmanaged resources.</summary>
public void Dispose()
{
if (IsDisposed)
return;
// Lose reference but don't kill it.
if (Database != null)
{

View File

@@ -174,11 +174,18 @@ namespace DynamORM
/// 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>

View File

@@ -1449,6 +1449,9 @@ namespace DynamORM.Helpers.Dynamics
/// </summary>
public void Dispose()
{
if (IsDisposed)
return;
IsDisposed = true;
if (_uncertainResult != null)

View File

@@ -127,11 +127,14 @@ namespace DynamORM.Mapper
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(
Expression.TypeAs(objParm, property.DeclaringType),
target,
property.Name),
typeof(object)), objParm).Compile();
}