Question

What is the maximun that LINQ expression Tree can do?

Can it define a class? How about a method, with all the declared name, modifiers, parametertype and return type?

Must the program always define the tree himself? Is it possible to generate the tree from a given C# file?

Where can I get resources to learn about writing basic to advanced Expression Tree and Expression Tree Visitor? (articles and videos will be great)

Thanks for those who are able to help...

Was it helpful?

Solution

In C# 3, expression trees can represent expressions. Hence the name. And they are further restricted to a subset of C# expressions -- no assignment expressions, no expressions involving pointer types, and so on.

In the libraries that will ship with C# 4, we have extended the expression tree library to also support statement trees. However, C# 4 will NOT automatically translate a statement-lambda into a "statement tree".

That is an obvious and useful feature which we simply did not have time to get to for C# 4. We'll consider it for hypothetical future versions. If you have a really great user scenario for statement trees, I'd love to hear it.

The obvious further extension to all that is declaration trees, which would represent class declarations, struct declarations, and so on. Having total homoiconicity between the C# language and the expression tree library would be awesome. It would enable all kinds of interesting metaprogramming scenarios. But that will not happen any time soon, so do not get your hopes up. That's more of a long-term dream of mine which might never happen.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top