using System; namespace ScreenConnect; public class Lazy { public static Lazy CreateResolved(T resolvedValue) { return new Lazy(() => resolvedValue); } public static Lazy Create(Func selector) { return new Lazy(selector); } public static Lazy CreateUtcNow() { return new Lazy(() => DateTime.UtcNow); } public static Lazy CreateMillisecondCount() { return new Lazy(() => Singleton.Instance.GetMillisecondCount()); } public static Lazy CreateMillisecondCountDifference(Lazy startMillisecondCount) { return new Lazy(() => Singleton.Instance.GetMillisecondCount() - startMillisecondCount.Value); } } public class Lazy { private Func selector; private T value; private bool hasResolvedValue; public T Value { get { if (!hasResolvedValue) { value = selector(); hasResolvedValue = true; } return value; } } public bool HasResolvedValue => hasResolvedValue; public Lazy(Func selector) { this.selector = selector.AssertArgumentNonNull("selector"); value = default(T); hasResolvedValue = false; } public T GetValueOrDefaultIfNotResolved() { return value; } public override string ToString() { return Value.ToString(); } }