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


well, following code self-explaining; want combine 2 expressions 1 using and operator. last line causes rune-time error:

additional information: variable 'y' of type 'system.string' referenced scope '', not defined

code:

expression<func<string, bool>> e1 = y => y.length < 100; expression<func<string, bool>> e2 = y => y.length < 200;  var e3 = expression.and(e1.body, e2.body);  var e4 = expression.lambda<func<string, bool>>(e3, e1.parameters.toarray()); e4.compile(); // <--- causes run-time error 

the problem parameter expression objects represents variable y in expressions e1 , e2 different. fact 2 variables named same , have same type not matter: e1.parameters.first() , e2.parameters.first() not same object.

this causes problem see: e1's parameter y available lambda<>, while e2's parameter y out of scope.

to fix problem use expression apis create e1 , e2. way able share parameter expression across them, eliminating problem of scope.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -