1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace CSharpUtil
- {
- /// <summary>
- /// 普通单例
- /// </summary>
- /// <typeparam name="T"></typeparam>
- public class Singleton<T> where T : Singleton<T>, new()
- {
- /// <summary>
- /// 单例
- /// </summary>
- private static T m_Instance;
- /// <summary>
- /// 实例
- /// </summary>
- public static T Instance
- {
- get
- {
- if (object.ReferenceEquals(Singleton<T>.m_Instance, null))
- {
- var obj = new T();
- Singleton<T>.m_Instance = obj;
- Container.Add(typeof(T).Name, obj);
- }
- return Singleton<T>.m_Instance;
- }
- }
- #region ' 内部容器 '
- static Dictionary<string, Object> _mC;
- static Dictionary<string, Object> Container
- {
- get
- {
- if (null == _mC)
- {
- _mC = new Dictionary<string, object>();
- }
- return _mC;
- }
- }
- #endregion
- }
- }
|