Harden disposal paths and test project metadata

This commit is contained in:
root
2026-02-23 21:31:07 +01:00
parent a2fd695738
commit 03b7d06a14
10 changed files with 192 additions and 122 deletions

View File

@@ -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>

View File

@@ -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
}
}
}

View File

@@ -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
}
}
}

View File

@@ -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
}
}
}

View File

@@ -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
}
}
}

View File

@@ -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
}
}
}

View File

@@ -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&lt;ProcResult&gt;(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;
}
}
}

View File

@@ -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
}
}

View File

@@ -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
}
}
}

View File

@@ -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
}
}
}