Expression To String and Expression Tree Visualizer
This project provides the following:
Extension methods to create a C# or VB.NET code-like string representation, of expression trees or expression tree parts (.NET Standard library)
A debugging visualizer for expression trees / expression tree parts
Note: Tested with VS 2017, which only supports custom visualizers in .NET Framework projects
Installation: The visualizer DLL and the dependent DLL (MultiSelectTreeView.DLL), on the release page, should be placed in the appropriate folder, as described here. It may be necessary to unblock the DLLs.
String representations of expression trees
Expression<Func<bool>> expr = () => true;
Console.WriteLine(expr.ToString("C#"));
// prints: () => true
Console.WriteLine(expr.ToString("Visual Basic"));
// prints: Function() TrueFeatures:
-
Support for outputting C#- and VB.NET-style pseudocode (with more to come)
-
Extension methods are rendered as instance methods
Expression<Func<int, int>> expr = x => Enumerable.Range(1, x).Select(y => x * y).Count(); Console.WriteLine(expr.ToString("C#")); // prints: (int x) => Enumerable.Range(1, x).Select((int y) => x * y).Count()
-
Closed-over variables are rendered as simple identifiers (instead of member access on the hidden compiler-generated class)
var i = 7; var j = 8; Expression<Func<int>> expr = () => i + j; Console.WriteLine(expr.ToString("C#")); // prints: () => i + j
-
Special handling of calls to
String.ConcatandString.Formatvar name = "World"; Expression<Func<string>> expr = () => string.Format("Hello, {0}!", name); Console.WriteLine(expr.ToString("C#")); // prints: () => $"Hello, {name}!"
-
Supports the full range of types in
System.Linq.Expressions, including .NET 4 expression types, andDynamicExpression
Visual Studio debugger visualizer for expression trees
The UI consists of three parts:
-
Tree view of the various parts of an expression tree
-
Source code view, using the above
ExpressionToStringlibrary -
End nodes -- nodes in the expression tree which are not composed of other expressions
- Parameters
- Closed-over variables
- Constant expressions
Features:
-
Live switching between C# and VB.NET
-
Selection syncing when selecting from the tree:
from source code:
and from end nodes:
Feedback
- Star the project, and/or upvote the reddit post
- File an issue
Credits
- John M. Wright's series on writing debugger visualizers
- Multiple-selection treeview is provided by MultiSelectTreeView
- ReadableExpressions
- Greenshot and ScreenToGIF for the screenshots




