Skip to main content
1 of 5
Nkosi
  • 3.2k
  • 16
  • 25

Why not wrap a Lazy<T> and then lazy load the Lazy<T> in your Get

public class MyLazy {
    private object lazy;
    private object _Lock = new object();

    public T Get<T>(Func<T> factory) {
        if (lazy == null) {
            lock (_Lock) {
                if (lazy == null) {
                    lazy = new Lazy<T>(factory);
                }
            }
        }
        return ((Lazy<T>)lazy).Value;
    }
}
Nkosi
  • 3.2k
  • 16
  • 25