variable '' of type '' referenced from scope '', but it is not defined

前端 未结 3 1385
生来不讨喜
生来不讨喜 2020-12-01 17:42

Well, the following code is self-explaining; I want to combine two expressions into one using And operator. The last line causes rune-time the error:

3条回答
  •  一向
    一向 (楼主)
    2020-12-01 18:36

    The problem is that parameter expression objects that represents variable y in expressions e1 and e2 are different. The fact that the two variables are named the same and have the same type does not matter: e1.Parameters.First() and e2.Parameters.First() is not the same object.

    This causes the problem that you see: only e1's parameter y is available to Lambda<>, while e2's parameter y is out of scope.

    To fix this problem use Expression APIs to create e1 and e2. This way you would be able to share the parameter expression across them, thus eliminating the problem of scope.

提交回复
热议问题