i want validate assumption linq expression api not have means create expression represents creation of local variable.
in other words, cannot create expression represent:
int local;
since variable declaration statement, , api not support statement lambdas. state lambda expression, represented linq expression api (and not delegate instance) can work parameters receives , captured variables receives via closure.
is assumption (based on few months of practice of linq expression api) correct?
false. there overloads of expression.block it.
what true can't create lambda expression through use of c# compiler has variable, limitation of compiler.
so can't
expression<func<int>> exp = () => { int v = 1; return v; };
but can
var variable = expression.variable(typeof(int)); var lambda = expression.lambda<func<int>>( expression.block( new[] { variable }, expression.assign(variable, expression.constant(1)), variable)); // lambda expressions, there implicit // return of last value "loaded" on stack
since variable declaration statement, , api not support statement lambdas.
this true in .net < 4.0 . in .net 4.0 microsoft added expression
methods build can present in body of method (there missing "things", unsafe code keywords/operators, plus there primitives there aren't complex constructs for
or lock
, can built on top of other constructs). note 90% of added things incompatible linq-to-sql/ef.
Comments
Post a Comment