SingletonPropertyClass.cs 1003 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. namespace IFramework.Singleton
  3. {
  4. /// <summary>
  5. /// 单例属性类
  6. /// </summary>
  7. /// <typeparam name="T"></typeparam>
  8. public abstract class SingletonPropertyClass<T> : Unit, ISingleton where T : SingletonPropertyClass<T>
  9. {
  10. /// <summary>
  11. /// 实例
  12. /// </summary>
  13. protected static T instance { get { return SingletonProperty<T>.instance; } }
  14. /// <summary>
  15. /// ctor
  16. /// </summary>
  17. protected SingletonPropertyClass() { }
  18. /// <summary>
  19. /// 初始化
  20. /// </summary>
  21. protected abstract void OnSingletonInit();
  22. /// <summary>
  23. /// 注销
  24. /// </summary>
  25. public override void Dispose()
  26. {
  27. base.Dispose();
  28. if (!disposed)
  29. {
  30. SingletonProperty<T>.Dispose();
  31. }
  32. }
  33. void ISingleton.OnSingletonInit()
  34. {
  35. OnSingletonInit();
  36. }
  37. }
  38. }