A simple library to bring GoLang's `defer` functionality to .NET! (Legacy app version: only implements for `IDisposable`)
$ dotnet add package DotNetDefer.LegacyA simple library to bring GoLang's defer functionality to .NET!
This version of DotNetDefer targets netstandard1.0 and only implements IDisposable - for use with older projects.
Standard Actions: (primary use-case)
using DotNetDefer;
class Program
{
static void Main(string[] args)
{
var process = new Process();
process.Start();
using var defer = new Defer(process.Kill);
// Do some work
}
}
Use with Func<T>
using DotNetDefer;
class Program
{
static void Main(string[] args)
{
var process = new Process();
process.Start();
var defer = new Defer(() =>
{
process.Kill();
return process.ExitCode;
});
using (defer)
{
// Do some work
}
var exitCode = defer.Result;
}
}