Show / Hide Table of Contents

Struct Scope

Represents a collection of callbacks to be executed at the end of the lexical scope.

Implements
IDisposable
IAsyncDisposable
Inherited Members
ValueType.Equals(object)
ValueType.GetHashCode()
ValueType.ToString()
object.Equals(object, object)
object.GetType()
object.ReferenceEquals(object, object)
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 Source

Defer(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

callback is null.

| Edit this page View Source

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

callback is null.

| Edit this page View Source

Dispose()

Executes all attached callbacks synchronously.

Declaration
public void Dispose()
| Edit this page View Source

DisposeAsync()

Executes all attached callbacks asynchronously.

Declaration
public readonly ValueTask DisposeAsync()
Returns
Type Description
ValueTask

The task representing asynchronous execution.

| Edit this page View Source

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

disposable is null.

| Edit this page View Source

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

disposable is null.

Implements

IDisposable
IAsyncDisposable

Extension Methods

BasicExtensions.IsBetween<T, TLowerBound, TUpperBound>(T, TLowerBound, TUpperBound)
BasicExtensions.IsOneOf<T>(T, ReadOnlySpan<T>)
Collection.ToAsyncEnumerator<TEnumerator, T>(TEnumerator, CancellationToken)
Collection.ToClassicEnumerator<TEnumerator, T>(TEnumerator)
Enumerator.Skip<TEnumerator, T>(ref TEnumerator, int)
ExpressionBuilder.Const<T>(T)
  • Edit this page
  • View Source
☀
☾
In this article
Back to top
Supported by the .NET Foundation
☀
☾