Skip to main content
2 of 5
added 109 characters in body
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;
    }
}

Taking advantage of existing features that have been tried and tested instead of trying to roll your own.

Nkosi
  • 3.2k
  • 16
  • 25