Created
August 3, 2017 05:17
-
-
Save xbotter/e34df693ad431d792489f86e6dfb8bda to your computer and use it in GitHub Desktop.
Lazy Load Class
This file contains 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 class LazyLoad<T> | |
{ | |
private readonly Lazy<T> _lazy; | |
private T _value; | |
public LazyLoad(Func<T> valueFactory) | |
{ | |
_lazy = new Lazy<T>(valueFactory); | |
} | |
public T Value | |
{ | |
get | |
{ | |
if (!_lazy.IsValueCreated) | |
{ | |
_value = _lazy.Value; | |
} | |
return _value; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment