namespace Feng.FramWorkDesign标签:mInstance,继承,模式,static,单例,var,null,type,ctor From: https://www.cnblogs.com/TriggerF/p/17654801.html
{
public class Singleton<T> where T: Singleton<T>
{
private static T mInstance;
public static T MInstance
{
get
{
if (mInstance==null)
{
var type = typeof(T);
var ctors = type.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic);
var ctor = Array.Find(ctors, c => c.GetParameters().Length == 0);
if (ctor==null)
{
throw new Exception("Non Public Constructor Not Fount in "+type.Name);
}
mInstance= ctor.Invoke(null) as T;
}
return mInstance;
}
}
}
}