Skip to content

Instantly share code, notes, and snippets.

@nmcc
Created June 5, 2017 08:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nmcc/ba387495617c235823b7a71d2d05a8e5 to your computer and use it in GitHub Desktop.
Save nmcc/ba387495617c235823b7a71d2d05a8e5 to your computer and use it in GitHub Desktop.
Lazy<T> for IDisposable classes
public static class LazyExtensions
{
public static void Dispose<T>(this Lazy<T> target) where T : IDisposable
{
if (target?.IsValueCreated ?? false)
{
target.Value.Dispose();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment