Class Disposable
Provides implementation of dispose pattern.
Inheritance
Implements
Inherited Members
Namespace: DotNext
Assembly: DotNext.dll
Syntax
public abstract class Disposable : IDisposable
Properties
| Edit this page View SourceDisposedTask
Gets a task representing ObjectDisposedException exception.
Declaration
protected Task DisposedTask { get; }
Property Value
Type | Description |
---|---|
Task |
IsDisposed
Indicates that this object is disposed.
Declaration
protected bool IsDisposed { get; }
Property Value
Type | Description |
---|---|
bool |
IsDisposing
Indicates that DisposeAsync() is called but not yet completed.
Declaration
protected bool IsDisposing { get; }
Property Value
Type | Description |
---|---|
bool |
IsDisposingOrDisposed
Indicates that DisposeAsync() is called.
Declaration
protected bool IsDisposingOrDisposed { get; }
Property Value
Type | Description |
---|---|
bool |
Methods
| Edit this page View SourceCreateException()
Creates a new instance of ObjectDisposedException class.
Declaration
protected ObjectDisposedException CreateException()
Returns
Type | Description |
---|---|
ObjectDisposedException | A new instance of the exception that can be thrown by the caller. |
Dispose()
Releases all resources associated with this object.
Declaration
public void Dispose()
Dispose(bool)
Releases managed and unmanaged resources associated with this object.
Declaration
protected virtual void Dispose(bool disposing)
Parameters
Type | Name | Description |
---|---|---|
bool | disposing | true if called from Dispose(); false if called from finalizer ~Disposable(). |
Dispose(IEnumerable<IDisposable?>)
Disposes many objects.
Declaration
public static void Dispose(IEnumerable<IDisposable?> objects)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<IDisposable> | objects | An array of objects to dispose. |
DisposeAsync()
Releases managed resources associated with this object asynchronously.
Declaration
protected ValueTask DisposeAsync()
Returns
Type | Description |
---|---|
ValueTask | The task representing asynchronous execution of this method. |
Remarks
If derived class implements IAsyncDisposable then DisposeAsync() can be trivially implemented through delegation of the call to this method.
DisposeAsync(IEnumerable<IAsyncDisposable?>)
Disposes many objects.
Declaration
public static ValueTask DisposeAsync(IEnumerable<IAsyncDisposable?> objects)
Parameters
Type | Name | Description |
---|---|---|
IEnumerable<IAsyncDisposable> | objects | An array of objects to dispose. |
Returns
Type | Description |
---|---|
ValueTask | The task representing asynchronous execution of this method. |
DisposeAsync(params IAsyncDisposable?[])
Disposes many objects in safe manner.
Declaration
public static ValueTask DisposeAsync(params IAsyncDisposable?[] objects)
Parameters
Type | Name | Description |
---|---|---|
IAsyncDisposable[] | objects | An array of objects to dispose. |
Returns
Type | Description |
---|---|
ValueTask | The task representing asynchronous execution of this method. |
DisposeAsyncCore()
Releases managed resources associated with this object asynchronously.
Declaration
protected virtual ValueTask DisposeAsyncCore()
Returns
Type | Description |
---|---|
ValueTask | The task representing asynchronous execution of this method. |
Remarks
This method makes sense only if derived class implements IAsyncDisposable interface.
Dispose<T>(ReadOnlySpan<T>)
Disposes many objects in safe manner.
Declaration
public static void Dispose<T>(ReadOnlySpan<T> objects) where T : IDisposable?
Parameters
Type | Name | Description |
---|---|---|
ReadOnlySpan<T> | objects | An array of objects to dispose. |
Type Parameters
Name | Description |
---|---|
T |
~Disposable()
Finalizes this object.
Declaration
protected ~Disposable()
GetDisposedTask<T>()
Returns a task representing ObjectDisposedException exception.
Declaration
protected Task<T> GetDisposedTask<T>()
Returns
Type | Description |
---|---|
Task<T> | The task representing ObjectDisposedException exception. |
Type Parameters
Name | Description |
---|---|
T | The type of the task. |
TryBeginDispose()
Starts disposing this object.
Declaration
protected bool TryBeginDispose()
Returns
Type | Description |
---|---|
bool | true if cleanup operations can be performed; false if the object is already disposing. |
TrySetDisposedException(TaskCompletionSource)
Attempts to complete the task with ObjectDisposedException exception.
Declaration
protected bool TrySetDisposedException(TaskCompletionSource source)
Parameters
Type | Name | Description |
---|---|---|
TaskCompletionSource | source | The task completion source. |
Returns
Type | Description |
---|---|
bool |
TrySetDisposedException<T>(TaskCompletionSource<T>)
Attempts to complete the task with ObjectDisposedException exception.
Declaration
protected bool TrySetDisposedException<T>(TaskCompletionSource<T> source)
Parameters
Type | Name | Description |
---|---|---|
TaskCompletionSource<T> | source | The task completion source. |
Returns
Type | Description |
---|---|
bool |
Type Parameters
Name | Description |
---|---|
T | The type of the task. |