/// <summary> /// 单例类助手 /// </summary> public sealed class SingletonHelper<T> where T : new() { private static T instance = new T(); private static object locker = new object(); private SingletonHelper() { } /// <summary> /// 获取单例 /// </summary> /// <returns></returns> public static T GetInstance() { if (null == instance) { lock (locker) { if (null == instance) { instance = new T(); } } } return instance; } /// <summary> /// 设置单例 /// </summary> /// <param name=value></param> public void SetInstance(T value) { instance = value; } } |