Skip to content
String representation of expression trees and expression tree parts + debugging visualizer
Branch: master
Clone or download

README.md

Expression To String and Expression Tree Visualizer

This project provides the following:

  • NuGet Status Extension methods to create a C# or VB.NET code-like string representation, of expression trees or expression tree parts (.NET Standard library)
  • GitHub Release 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() True

Features:

  • 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.Concat and String.Format

    var 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, and DynamicExpression

Visual Studio debugger visualizer for expression trees

Screenshot

The UI consists of three parts:

  1. Tree view of the various parts of an expression tree

  2. Source code view, using the above ExpressionToString library

  3. 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

    Language switch

  • Selection syncing when selecting from the tree:

    Selection sync from tree

    from source code:

    Selection sync from source code

    and from end nodes:

    Selection sync from end nodes

Feedback

  • Star the project, and/or upvote the reddit post
  • File an issue

Credits

You can’t perform that action at this time.