Skip to content

Instantly share code, notes, and snippets.

@xbotter
Created August 3, 2017 05:17
Show Gist options
  • Save xbotter/e34df693ad431d792489f86e6dfb8bda to your computer and use it in GitHub Desktop.
Save xbotter/e34df693ad431d792489f86e6dfb8bda to your computer and use it in GitHub Desktop.
Lazy Load Class
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