SingleInstance.cs 517 B

12345678910111213141516171819202122
  1. using System;
  2. namespace SAGA.DotNetUtils.Data
  3. {
  4. public class SingleInstance<T> where T: new()
  5. {
  6. private static T m_Instance;
  7. public static T Instance
  8. {
  9. get
  10. {
  11. if (SingleInstance<T>.m_Instance == null)
  12. {
  13. SingleInstance<T>.m_Instance = (default(T) == null) ? Activator.CreateInstance<T>() : default(T);
  14. }
  15. return SingleInstance<T>.m_Instance;
  16. }
  17. }
  18. }
  19. }