namespace ET.Util { using System; /// /// A base class for the singleton design pattern. /// https://www.codeproject.com/Articles/572263/A-Reusable-Base-Class-for-the-Singleton-Pattern-in /// /// Class type of the singleton public abstract class SingletonBase where T : class { #region Members /// /// Static instance. Needs to use lambda expression /// to construct an instance (since constructor is private). /// private static readonly Lazy sInstance = new Lazy(() => CreateInstanceOfT()); #endregion #region Properties /// /// Gets the instance of this singleton. /// public static T Instance { get { return sInstance.Value; } } #endregion #region Methods /// /// Creates an instance of T via reflection since T's constructor is expected to be private. /// /// private static T CreateInstanceOfT() { return Activator.CreateInstance(typeof(T)) as T; //return new T(); } #endregion } }