Created
June 5, 2017 08:02
-
-
Save nmcc/ba387495617c235823b7a71d2d05a8e5 to your computer and use it in GitHub Desktop.
Lazy<T> for IDisposable classes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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