Alexey Romanov
Alexey Romanov

Reputation: 170755

Expression trees for code which doesn't type check

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.

Upvotes: 1

Views: 122

Answers (1)

Barry Kelly
Barry Kelly

Reputation: 42152

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.

Upvotes: 1

Related Questions