Singleton-T-.cs 324 B

1234567891011121314151617181920
  1. using System;
  2. public class Singleton<T>
  3. {
  4. protected static readonly T ms_instance = Activator.CreateInstance<T>();
  5. public static T Instance
  6. {
  7. get
  8. {
  9. return Singleton<T>.ms_instance;
  10. }
  11. }
  12. protected Singleton()
  13. {
  14. this.OnInstanceCreate();
  15. }
  16. protected virtual void OnInstanceCreate()
  17. {
  18. }
  19. }