| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 | 
							- using System;
 
- using System.Threading;
 
- #if COMBAT_SERVER
 
- using Common.Combat;
 
- #endif
 
- using Fort23.UTool;
 
- namespace Utility
 
- {
 
-     public class Singleton<T> : IDisposable where T : new()
 
-     {
 
-         static object m_lock = new object();
 
- #if COMBAT_SERVER
 
-         private static Map<int, T> _threadingInstance = new Map<int, T>();
 
- #endif
 
- #if !COMBAT_SERVER
 
-         protected static T m_instance;
 
-         public static T Instance
 
-         {
 
-             get
 
-             {
 
-                 
 
-                 if (m_instance == null)
 
-                 {
 
-                     lock (m_lock)
 
-                     {
 
-                         if (m_instance == null)
 
-                         {
 
-                             m_instance = new T();
 
-                         }
 
-                     }
 
-                 }
 
-                 return m_instance;
 
-             }
 
-             set { m_instance = value; }
 
-         }
 
-              public virtual void Dispose()
 
-         {
 
-            
 
-             ProDispose();
 
-             Instance = (T) (object) null;
 
-         }
 
- #else
 
-         public static T Instance
 
-         {
 
-             get
 
-             {
 
-                 int id = Thread.CurrentThread.ManagedThreadId;
 
-                 if (typeof(T) == typeof(ConfigComponent) || typeof(T) == typeof(CombatPersistenceData))
 
-                 {
 
-                     id = 100;
 
-                 }
 
-                 if (_threadingInstance.TryGetValue(id, out T VALUE))
 
-                 {
 
-                     return VALUE;
 
-                 }
 
-                 lock (_threadingInstance)
 
-                 {
 
-                     if (_threadingInstance.TryGetValue(id, out T VALUE2))
 
-                     {
 
-                         return VALUE2;
 
-                     }
 
-                     else
 
-                     {
 
-                         // LogTool.Log("新建示例"+id+"__"+typeof(T));
 
-                         T iInstance = new T();
 
-                         _threadingInstance.Add(id, iInstance);
 
-                         return iInstance;
 
-                     }
 
-                 }
 
-             }
 
-         }
 
-         public virtual void Dispose()
 
-         {
 
-             ProDispose();
 
-             lock (_threadingInstance)
 
-             {
 
-                 int id = Thread.CurrentThread.ManagedThreadId;
 
-                 _threadingInstance.Remove(id);
 
-             }
 
-         }
 
- #endif
 
-         protected virtual void ProDispose()
 
-         {
 
-         }
 
-     }
 
- }
 
 
  |