views:

75

answers:

1

Is it possible to construct an expression tree in .NET 3.5 from code like

Expression expr = () => (true + new object())

? It seems to be impossible, since "A compiler-generated expression tree is always rooted in a node of type Expression", but I may be missing something.

Obviously, such a tree can be constructed manually.

+1  A: 

No it is not obvious that such a tree can be constructed manually. The expression the tree is representing is type-checked as it is being constructed. As such, what you ask is not possible and the answer is no.

Barry Kelly