Create predicate with a BinaryExpression containing multiple parameters

前端 未结 3 594
旧巷少年郎
旧巷少年郎 2021-01-27 10:52

is it possible to dynamically generate such a predicate using LambdaExpressions?

Expression> predicate = t =>
    t         


        
3条回答
  •  抹茶落季
    2021-01-27 11:15

    When you build an expression with nested lambda's the inner lambda's expressions will be able to access the outer lambda's parameters. It works the same way with Expression lambdas as with regular C# lambdas.

    If you are working with Expression lambdas and trying to combine them, you'll need to work with them at the API level (do it by hand), and not expect the automatic C# language syntax to Expression conversion to help you out.

    One thing to note: when you created the two original lambdas (via conversion to Expression), they each got their own ParameterExpression instances, which will make it impossible to combine them because both bodies will need to be referencing the same instance (unless you replace one for the other using an ExpressionVisitor.)

提交回复
热议问题