Skip to content

Available renderers

Zev Spitz edited this page Jan 29, 2022 · 15 revisions

There are currently 8 available renderers, which can be referred to either by a string or an enum value from BuiltinRenderer.

Renderer String Enum Language
C# pseudo-code "C#" BuiltinRenderer.CSharp Ignored
Expression<Func<Person, bool>> expr = p => p.DOB.DayOfWeek == DayOfWeek.Tuesday;
Console.WriteLine(expr.ToString("C#"));
/*
    (Person p) => p.DOB.DayOfWeek == DayOfWeek.Tuesday
*/
Visual Basic pseudo-code "Visual Basic" BuiltinRenderer.VisualBasic Ignored
Console.WriteLine(expr.ToString("Visual Basic"));
/*
    Function(p As Person) p.DOB.DayOfWeek = DayOfWeek.Tuesday
*/
Factory methods which produce this expression "Factory methods" BuiltinRenderer.FactoryMethods Required
Console.WriteLine(expr.ToString("Factory methods"));
/*
    // using static System.Linq.Expressions.Expression

    var p = Parameter(
        typeof(Person),
        "p"
    );

    Lambda(
        Equal(
            Convert(
                MakeMemberAccess(
                    MakeMemberAccess(p,
                        typeof(Person).GetProperty("DOB")
                    ),
                    typeof(DateTime).GetProperty("DayOfWeek")
                ),
                typeof(int)
            ),
            Constant(2)
        ),
        p
    )
*/
Dynamic LINQ equivalent of the expression "Dynamic LINQ" BuiltinRenderer.DynamicLinq Required
Expression<Func<Person, bool>> expr1 = p => 
    p.DOB.DayOfWeek == DayOfWeek.Tuesday || 
    p.DOB.DayOfWeek == DayOfWeek.Thursday;
Console.WriteLine(expr1.ToString("Dynamic LINQ", "C#"));
/*
    "DOB.DayOfWeek in (DayOfWeek.Tuesday, DayOfWeek.Thursday)"
*/

Expression expr2 = Enumerable.Empty<Person>()
    .AsQueryable()
    .Where(x => x.Age <= 20)
    .OrderBy(x => x != null && x.LastName != null ? x.LastName[0] : ' ')
    .ThenBy(x => x != null && x.FirstName != null ? x.FirstName[0] : ' ')
    .Expression;
Console.WriteLine(expr2.ToString("Dynamic LINQ", "C#"));
/*
    #EnumerableQuery<Person>.Where("Age <= 20").OrderBy("np(LastName[0], \' \')").ThenBy("np(FirstName[0], \' \')")    
*/
Tree-like text view of NodeType, Type and Name "Textual tree" BuiltinRenderer.TextualTree Optional
Expression<Func<Person, bool>> expr3 = p => true;
Console.WriteLine(expr2.ToString("Textual tree", "C#"));
/*
    Lambda (Func<Person, bool>)
        · Parameters[0] - Parameter (Person) p
        · Body - Constant (bool) = true
*/
Object graph, described using object/collection initializers "Object notation" BuiltinRenderer.ObjectNotation Required
Console.WriteLine(expr3.ToString("Object notation", "C#"));
/*
    var p = new ParameterExpression {
        Type = typeof(Person),
        IsByRef = false,
        Name = "p"
    };

    new Expression<Func<Person, bool>> {
        NodeType = ExpressionType.Lambda,
        Type = typeof(Func<Person, bool>),
        Parameters = new ReadOnlyCollection<ParameterExpression> {
            p
        },
        Body = new ConstantExpression {
            Type = typeof(bool),
            Value = true
        },
        ReturnType = typeof(bool)
    }
*/
.NET ToString "ToString" BuiltinRenderer.ToStringRenderer Ignored
Console.WriteLine(expr3.ToString("ToString"));
/*
    p => True
*/
.NET DebugView "DebugView" BuiltinRenderer.DebugView Ignored
Console.WriteLine(expr3.ToString("DebugView"));
/*
    .Lambda #Lambda1<System.Func`2[_tests.Person,System.Boolean]>(_tests.Person $p) {
        True
    }
*/