Struct Scope
Represents a collection of callbacks to be executed at the end of the lexical scope.
Inherited Members
Namespace: DotNext.Runtime.CompilerServices
Assembly: DotNext.dll
Syntax
public struct Scope : IDisposable, IAsyncDisposable
Remarks
This type allows to avoid usage of try-finally blocks within the code. It is suitable for asynchronous and synchronous scenarios. However, you should not pass an instance of this type as an argument to or return it from the method.
Methods
| Edit this page View SourceDefer(Action)
Attaches callback to this lexical scope.
Declaration
public void Defer(Action callback)
Parameters
| Type | Name | Description |
|---|---|---|
| Action | callback | The callback to be attached to the current scope. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
Defer(Func<ValueTask>)
Attaches callback to this lexical scope.
Declaration
public void Defer(Func<ValueTask> callback)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<ValueTask> | callback | The callback to be attached to the current scope. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
Dispose()
Executes all attached callbacks synchronously.
Declaration
public void Dispose()
DisposeAsync()
Executes all attached callbacks asynchronously.
Declaration
public readonly ValueTask DisposeAsync()
Returns
| Type | Description |
|---|---|
| ValueTask | The task representing asynchronous execution. |
RegisterForDispose(IDisposable)
Registers an object for disposal.
Declaration
public void RegisterForDispose(IDisposable disposable)
Parameters
| Type | Name | Description |
|---|---|---|
| IDisposable | disposable | The object to be disposed. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
RegisterForDisposeAsync(IAsyncDisposable)
Registers an object for asynchronous disposal.
Declaration
public void RegisterForDisposeAsync(IAsyncDisposable disposable)
Parameters
| Type | Name | Description |
|---|---|---|
| IAsyncDisposable | disposable | The object to be disposed asynchronously. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|