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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…