zspitz / ExpressionTreeToString

String representations of expression trees + library of expression tree objects
MIT License
151 stars 12 forks source link

Transition Dynamic LINQ writer/visitor output to actual code #82

Closed zspitz closed 3 years ago

zspitz commented 3 years ago

Currently, the Dynamic LINQ writer/visitor outputs a simple string. This means:

For example:

// using System.Dynamic.Linq.Core;

public c;lass Person {
    public string LastName {get;set;}
}

var expr = Enumerable.Empty<Person>().AsQueryable().Where("LastName = \"A\"").Expression;
Console.WriteLine(expr.ToString("Dynamic LINQ"));

prints an error, because the call to .Where is not valid within a selector, and thus not renderable.

Ideally, we'd like to see this:

#EnumerablePerson.AsQueryable().Where("LastName = \"A\"")

which shows the Dynamic LINQ method calls, and can be copied/pasted much more easily.

This would require knowledge of the language (C# / VB) for rendering string literals.

Related: #78,