Skip to content

Instantly share code, notes, and snippets.

@rossmurray
Created April 25, 2014 21:16
Show Gist options
  • Save rossmurray/11303553 to your computer and use it in GitHub Desktop.
Save rossmurray/11303553 to your computer and use it in GitHub Desktop.
Using method, much more composable than a using statement.
public static class DisposableExtensions
{
public static R Using<U,R>(this U disposable, Func<U,R> body) where U : IDisposable
{
try
{
return body(disposable);
}
finally
{
disposable.Dispose();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment