【发布时间】:2014-02-27 09:50:11
【问题描述】:
我正在尝试创建一个已编译的表达式委托来调用带有单个参数的构造函数,我收到以下异常:
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();
我相信我收到了异常,因为参数“值”不在 Expression.Block 范围内。
如何在 Expression.Block 中确定参数和构造函数表达式的范围?
【问题讨论】:
-
你能用 ctor 发布类型定义吗?
标签: c# .net reflection expression-trees