BlueSingleton.cs 466 B

12345678910111213141516171819202122
  1. namespace Blue
  2. {
  3. /// <summary>
  4. /// 单例模式的基类
  5. /// </summary>
  6. public class BlueSingleton<T> where T : BlueSingleton<T>, new()
  7. {
  8. private static T instance;
  9. public static T Instance
  10. {
  11. get
  12. {
  13. if (instance == null)
  14. {
  15. instance = new T();
  16. }
  17. return instance;
  18. }
  19. }
  20. }
  21. }