Skip to content

Commit a13f11f

Browse files
author
Oren (electricessence)
committed
Cleanup of AssertIsAlive method.
1 parent 6f50a79 commit a13f11f

File tree

3 files changed

+13
-29
lines changed

3 files changed

+13
-29
lines changed

DisposableStateBase.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,15 @@ public abstract class DisposableStateBase : IDisposalState
3535
protected int DisposalState => _disposeState;
3636
public bool WasDisposed => _disposeState != ALIVE && _disposeState != DISPOSE_CALLED;
3737

38+
protected bool AssertIsAlive()
39+
{
40+
if (WasDisposed)
41+
throw new ObjectDisposedException(GetType().ToString());
42+
43+
return true;
44+
}
45+
46+
3847
/* This is important because some classes might react to disposal
3948
* and still need access to the live class before it's disposed.
4049
* In addition, no events should exist during or after disposal. */

Extensions.cs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
*/
55

66
using System;
7-
using System.Buffers;
87
using System.Collections.Generic;
98
using System.Diagnostics.Contracts;
109
using System.Linq;
@@ -16,7 +15,7 @@ public static class DisposableExtensions
1615
public static bool AssertIsAlive(this IDisposalState state)
1716
{
1817
if (state.WasDisposed)
19-
throw new ObjectDisposedException(state.ToString());
18+
throw new ObjectDisposedException(state.GetType().ToString());
2019

2120
return true;
2221
}
@@ -53,28 +52,5 @@ public static void Dispose<T>(this ICollection<T> target, bool disposeContents =
5352
target.Clear();
5453
if (target is IDisposable t) t.Dispose();
5554
}
56-
57-
const int MaxPoolArraySize = 1024 * 1024;
58-
static void Dummy() { }
59-
60-
/// <summary>
61-
/// Rents a buffer from the ArrayPool but returns a DisposeHandler with the buffer as it's value.
62-
/// Facilitiates containing the temporary use of a buffer within a using block.
63-
/// If the mimimumLength exceeds 1024*1024, an array will be created at that length for use.
64-
/// </summary>
65-
/// <typeparam name="T">The type of the array.</typeparam>
66-
/// <param name="pool">The pool to get the array from.</param>
67-
/// <param name="minimumLength">The minimum length of the array.</param>
68-
/// <param name="clearArrayOnReturn">If true, will clear the array when it is returned to the pool.</param>
69-
/// <returns>A DisposeHandler containing an array of type T[] that is at least minimumLength in length.</returns>
70-
public static DisposeHandler<T[]> RentDisposable<T>(this ArrayPool<T> pool, int minimumLength, bool clearArrayOnReturn = false)
71-
{
72-
// If the size is too large, facilitate getting an array but don't manage the pool.
73-
if (minimumLength > MaxPoolArraySize)
74-
return new DisposeHandler<T[]>(new T[minimumLength], Dummy);
75-
76-
var a = pool.Rent(minimumLength);
77-
return new DisposeHandler<T[]>(a, () => pool.Return(a, clearArrayOnReturn));
78-
}
7955
}
8056
}

Open.Disposable.csproj

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
<PackageProjectUrl>https://github.com/electricessence/Open.Disposable/</PackageProjectUrl>
1818
<RepositoryUrl>https://github.com/electricessence/Open.Disposable/</RepositoryUrl>
1919
<RepositoryType>git</RepositoryType>
20-
<Version>2.1.0</Version>
20+
<Version>2.2.0</Version>
2121
<PackageReleaseNotes></PackageReleaseNotes>
22-
<AssemblyVersion>2.1.0.0</AssemblyVersion>
23-
<FileVersion>2.1.0.0</FileVersion>
22+
<AssemblyVersion>2.2.0.0</AssemblyVersion>
23+
<FileVersion>2.2.0.0</FileVersion>
2424
<PackageLicenseExpression>MIT</PackageLicenseExpression>
2525
</PropertyGroup>
2626

@@ -41,7 +41,6 @@
4141

4242
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
4343
<PackageReference Include="System.Threading.Tasks.Extensions" Version="4.5.2" />
44-
<PackageReference Include="System.Memory" Version="4.5.3" />
4544
</ItemGroup>
4645

4746
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard2.1' ">

0 commit comments

Comments
 (0)