You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

43 line
791 B

  1. using System;
  2. using System.Reflection;
  3. using SUISS.Core.Utilities;
  4. namespace SUISSEngine
  5. {
  6. public abstract class Singleton<T> where T : Singleton<T>, new()
  7. {
  8. public Singleton()
  9. {
  10. }
  11. public static T Instance
  12. {
  13. get
  14. {
  15. if (Singleton<T>._instance == null)
  16. {
  17. try
  18. {
  19. Singleton<T>._instance = Activator.CreateInstance<T>();
  20. }
  21. catch (TargetInvocationException ex)
  22. {
  23. throw new Exception("Exception in initializer: " + typeof(T).GetCompatibleTypeInfo().FullName + "\n" + ex.InnerException.ToString());
  24. }
  25. }
  26. return Singleton<T>._instance;
  27. }
  28. }
  29. public static bool IsAvailable
  30. {
  31. get
  32. {
  33. return Singleton<T>._instance != null;
  34. }
  35. }
  36. private static T _instance;
  37. }
  38. }