Issue with closure variable capture in c# expression

后端 未结 2 1014
执笔经年
执笔经年 2020-12-31 13:38

I have a function which creates a delegate using expression trees. Within this expression I use a variable captured from multiple parameters passed in to the function. The a

2条回答
  •  臣服心动
    2020-12-31 14:21

    I think you're looking for Expression.Quote, which supports the variable capture in Lambda expressions. Basically the inner LambdaExpression (which will reference the captured variables) need to be wrapped in an Expression.Quote(...) call.

    Examples and discussion here: What does Expression.Quote() do that Expression.Constant() can’t already do?

提交回复
热议问题