Api Sandbox Utility DisposeAction
struct

DisposeAction

public sealed struct DisposeAction

A simple IDisposable that invokes an action when disposed. Useful for creating using-blocks with cleanup logic.

Constructors

DisposeAction(Action action)

Creates a new DisposeAction that will invoke the specified action on disposal.

action — The action to invoke when disposed

Methods

virtual Void Dispose()

Invokes the action specified in the constructor.

static IDisposable Create(Action action)

Factory method to create a DisposeAction as an IDisposable.

action — The action to invoke when disposed
returns — A disposable object that will invoke the action

Examples

using ( DisposeAction.Create( () => Console.WriteLine( "Cleanup!" ) ) )
{
    // Do work
} // "Cleanup!" is printed here
Assembly: Sandbox.System Namespace: Sandbox.Utility Full Name: Sandbox.Utility.DisposeAction