Update Em.cs

This commit is contained in:
陈思海 2026-04-30 10:16:33 +08:00
parent f6dbee5b5b
commit 03f479dc0e

View File

@ -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;
}