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.
ParameterExpressions
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
ConstantExpressions
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.
Type |
Suffix |
---|---|
U |
|
L |
|
UL |
|
D |
|
F |
|
M |
Examples
BlockExpression
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
Expression |
DebugView property |
---|---|
|
.Block() { "test" } |
|
.Block<System.Object>() { "test" } |
LambdaExpression
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 } |
LabelExpression
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: } |
Checked Operators
Checked operators are displayed with the "#" symbol in front of the operator. For example, the checked addition operator is displayed as #+.
Examples
See Also
Concepts
Expression Trees (C# and Visual Basic)