44 */
55
66using System ;
7- using System . Buffers ;
87using System . Collections . Generic ;
98using System . Diagnostics . Contracts ;
109using 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}
0 commit comments