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.