Update Em.cs
This commit is contained in:
parent
f6dbee5b5b
commit
03f479dc0e
@ -11,19 +11,16 @@ public static class InstanceFactory
|
||||
{
|
||||
if (!_constructorCache.TryGetValue(type, out var constructor))
|
||||
{
|
||||
// 楠岃瘉鏄惁瀛樺湪鍏叡鏃犲弬鏋勯€犲嚱鏁?
|
||||
var ctor = type.GetConstructor(Type.EmptyTypes);
|
||||
if (ctor == null)
|
||||
{
|
||||
throw new MissingMethodException(ZString.Format("Type {0} missing public parameterless constructor", type.Name));
|
||||
}
|
||||
|
||||
// 鏋勫缓琛ㄨ揪寮忔爲锛歯ew T()
|
||||
var newExpr = Expression.New(ctor);
|
||||
var lambda = Expression.Lambda<Func<object>>(newExpr);
|
||||
constructor = lambda.Compile();
|
||||
|
||||
// 缂撳瓨濮旀墭
|
||||
_constructorCache[type] = constructor;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user