-
Notifications
You must be signed in to change notification settings - Fork 11
Available renderers
Zev Spitz edited this page Sep 30, 2020
·
15 revisions
There are currently 5 available renderers, which can be referred to either by a string or an enum value from BuiltinRenderer
.
- String:
"C#"
- Enum:
BuiltinRenderer.CSharp
Console.WriteLine(expr.ToString("C#"));
/*
(Person p) => p.DOB.DayOfWeek == DayOfWeek.Tuesday
*/
- String:
"Visual Basic"
- Enum:
BuiltinRenderer.VisualBasic
Console.WriteLine(expr.ToString("Visual Basic"));
/*
Function(p As Person) p.DOB.DayOfWeek = DayOfWeek.Tuesday
*/
The factory method calls used to generate the expression, or one very much like it:
- String:
"Factory methods"
- Enum:
BuiltinRenderer.FactoryMethods
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
)
*/
Describes objects and collections using initializer syntax:
- String:
"Object notation"
- Enum:
BuiltinRenderer.ObjectNotation
Console.WriteLine(expr.ToString("Object notation"));
/*
new Expression<Func<Person, bool>> {
NodeType = ExpressionType.Lambda,
Type = typeof(Func<Person, bool>),
Parameters = new ReadOnlyCollection<ParameterExpression> {
new ParameterExpression {
Type = typeof(Person),
IsByRef = false,
Name = "p"
}
},
Body = new BinaryExpression {
NodeType = ExpressionType.Equal,
Type = typeof(bool),
Left = new UnaryExpression {
NodeType = ExpressionType.Convert,
Type = typeof(int),
Operand = new MemberExpression {
Type = typeof(DayOfWeek),
Expression = new MemberExpression {
Type = typeof(DateTime),
Expression = new ParameterExpression {
Type = typeof(Person),
IsByRef = false,
Name = "p"
},
Member = typeof(Person).GetProperty("DOB")
},
Member = typeof(DateTime).GetProperty("DayOfWeek")
}
},
Right = new ConstantExpression {
Type = typeof(int),
Value = 2
}
},
ReturnType = typeof(bool)
}
*/
Describes the structure of the expression tree: node type, reflection type, name and value, as appropriate
- String:
"Textual tree"
- Enum:
BuiltinRenderer.TextualTree
Console.WriteLine(expr.ToString("Textual tree"));
/*
Lambda (Func<Person, bool>)
Parameters[0] - Parameter (Person) p
Body - Equal (bool)
Left - Convert (int)
Operand - MemberAccess (DayOfWeek) DayOfWeek
Expression - MemberAccess (DateTime) DOB
Expression - Parameter (Person) p
Right - Constant (int) = 2
*/
- String:
"ToString"
- Enum:
BuiltinRenderer.ToStringRenderer
Console.WriteLine(expr.ToString("ToString"));
/*
p => (Convert(p.DOB.DayOfWeek, Int32) == 2)
*/
- String:
"DebugView"
- Enum:
BuiltinRenderer.DebugView
.Lambda #Lambda1<System.Func`2[_tests.Person,System.Boolean]>(_tests.Person $p) {
(System.Int32)($p.DOB).DayOfWeek == 2
}