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.
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
namespace S3Demo.Helper
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 单例模式
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <typeparam name="T">//new(),new不支持非公共的无参构造函数 </typeparam>
|
|
|
|
|
// Token: 0x0200016F RID: 367
|
|
|
|
|
public abstract class SingletonHelper<T> where T : class
|
|
|
|
|
{
|
|
|
|
|
private static T sInstance;
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 创建获取实例
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
public static T Instance()
|
|
|
|
|
{
|
|
|
|
|
Type typeFromHandle = typeof(T);
|
|
|
|
|
lock (typeFromHandle)
|
|
|
|
|
{
|
|
|
|
|
if (SingletonHelper<T>.sInstance == null)
|
|
|
|
|
{
|
|
|
|
|
SingletonHelper<T>.sInstance = (Activator.CreateInstance(typeof(T), true) as T);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return SingletonHelper<T>.sInstance;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|