Debugging Expression Trees (C# and Visual Basic)
You can analyze the structure and content of expression trees when you debug your applications. To get a quick overview of the expression tree structure, you can use the DebugView property, which is available only in debug mode. For more information about debugging, see Debugging in Visual Studio.
To better represent the content of expression trees, the DebugView property uses Visual Studio visualizers. For more information, see Visualizers.
To open a visualizer for an expression tree
Click the magnifying glass icon that appears next to the DebugView property of an expression tree in DataTips, a Watch window, the Autos window, or the Locals window.
A list of visualizers is displayed.
Click the visualizer you want to use.
Each expression type is displayed in the visualizer as described in the following sections.
ParameterExpression variable names are displayed with a "$" symbol at the beginning.
If a parameter does not have a name, it is assigned an automatically generated name, such as $var1 or $var2.
Examples
For ConstantExpression objects that represent integer values, strings, and null, the value of the constant is displayed.
For numeric types that have standard suffixes as C# literals, the suffix is added to the value. The following table shows the suffixes associated with various numeric types.
Examples
Expression | DebugView property |
|---|---|
int num = 10;
ConstantExpression expr = Expression.Constant(num);
Dim num as Integer= 10 Dim expr As ConstantExpression = Expression.Constant(num) | 10 |
double num = 10;
ConstantExpression expr = Expression.Constant(num);
Dim num As Double = 10 Dim expr As ConstantExpression = Expression.Constant(num) | 10D |
If the type of a BlockExpression object differs from the type of the last expression in the block, the type is displayed in the DebugInfo property in angle brackets (< and >). Otherwise, the type of the BlockExpression object is not displayed.
Examples
LambdaExpression objects are displayed together with their delegate types.
If a lambda expression does not have a name, it is assigned an automatically generated name, such as #Lambda1 or #Lambda2.
Examples
Expression | DebugView property |
|---|---|
.Lambda #Lambda1<System.Func'1[System.Int32]>() { 1 } | |
.Lambda SampleLambda<System.Func'1[System.Int32]>() { 1 } |
If you specify a default value for the LabelExpression object, this value is displayed before the LabelTarget object.
The .Label token indicates the start of the label. The .LabelTarget token indicates the destination of the target to jump to.
If a label does not have a name, it is assigned an automatically generated name, such as #Label1 or #Label2.
Examples
Expression | DebugView property |
|---|---|
.Block() { .Goto SampleLabel { 0 }; .Label -1 .LabelTarget SampleLabel: } | |
.Block() { .Goto #Label1 { }; .Label .LabelTarget #Label1: } |