Skip to content

A simple library that attempts to bring GoLang's `defer` functionality to .NET

License

Notifications You must be signed in to change notification settings

DrEsteban/DotNetDefer

Repository files navigation

DotNetDefer

A simple library to bring GoLang's defer functionality to .NET!

  • DotNetDefer
    • Implements IDisposable and IAsyncDisposable, and can be used with Action, Func<T> Func<Task> and Func<Task<T>>
  • DotNetDefer.Legacy
    • Implements only IDisposable and can be used with Actions and Funcs

Usage

using DotNetDefer;

class Program
{
    static void Main(string[] args)
    {
      var process = new MyLongProcess();
      process.Start();
      using var defer = new Defer(() => process.Stop());
  
      // Do some work
    }
}

Installation

dotnet add package DrEsteban.DotNetDefer

Install-Package DrEsteban.DotNetDefer

There's also a version of the package that targets netstandard1.0 for compatibility with older projects. (E.g. projects that don't support IAsyncDisposable)

Install-Package DrEsteban.DotNetDefer.Legacy

About

A simple library that attempts to bring GoLang's `defer` functionality to .NET

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages