我試圖創建一個編譯表達式委託調用構造採取單一的參數,我收到以下異常:調用參數化的構造函數使用編譯表達
Additional information: variable 'value' of type 'MyType' referenced from scope '', but it is not defined
的代碼如下:
var constructorInfo = instanceType.GetConstructors().Skip(1).First();
ParameterExpression param = Expression.Parameter(genericArgument, "value");
Delegate constructorDelegate = Expression.Lambda(Expression.New(constructorInfo, new Expression[] { param })).Compile();
我相信我正在接受異常,因爲參數'value'沒有在Expression.Block中作用域。
如何限制Expression.Block中的參數&構造函數表達式?
您可以使用ctor發佈類型定義嗎? – Dennis