将语句集合编译为一个动作
Compiling statement collection to an action
所以假设我想return这样的动作...
public Action<T1, T2> BuildActionFrom(object[] stuff)
{
BinaryExpression[] expressions = BuildExpressions(stuff);
return (x,y) => {
foreach(var ex in expressions) ex(x,y);
};
}
...我该如何构建它,因为我在表达式构建 api 中找不到任何似乎允许我构建该 return 值的内容?
我的每个表达式都非常简单(基本的 属性 赋值等等),我只是不知道如何将它们组合在一起。
找到了...
Expression.Block(expressions);
...正是我要找的!
所以假设我想return这样的动作...
public Action<T1, T2> BuildActionFrom(object[] stuff)
{
BinaryExpression[] expressions = BuildExpressions(stuff);
return (x,y) => {
foreach(var ex in expressions) ex(x,y);
};
}
...我该如何构建它,因为我在表达式构建 api 中找不到任何似乎允许我构建该 return 值的内容?
我的每个表达式都非常简单(基本的 属性 赋值等等),我只是不知道如何将它们组合在一起。
找到了...
Expression.Block(expressions);
...正是我要找的!