Visualizing (.NET 3.5) Expressions

It’s a problem, when you work with Expression types in any way, to understand the structure of complex expressions and possibly recreate them. After all, there are 46 entries in the ExpressionType enum, many of them corresponding to their own Expression-derived type, all of those with their own specific properties… in other words, it’s not entirely intuitive.

To help visualization of Expressions, I have created the ExpressionDumper, which outputs any expression (by default) in a nice hierarchical way on the console. It shouldn’t be too hard to use the class with other output targets, and I’m placing it under GNU LGPL license for others to use (that allows commercial use, in case you’re not quite on top of all the various open source licenses). I’d appreciate being kept up to date with any further development you may do on it, but you don’t have to tell me if you don’t want to. With this source code

Expression<Predicate<Product>> expression = p => p.UnitPrice > 10;

the ExpressionDumper is going to produce this output (of course this is a very simple example, chosen for brevity):

LambdaExpression (
    ParameterExpression (p)
    BinaryExpression:GreaterThan (
      Method: Boolean op_GreaterThan(System.Decimal, System.Decimal)
        MemberExpression Product.UnitPrice (
            ParameterExpression (p)
        ConstantExpression (10)

Without further ado, here’s the download:

Have fun!

Sorry, this blog does not support comments.

I used various blog hosting services since this blog was established in 2005, but unfortunately they turned out to be unreliable in the long term and comment threads were lost in unavoidable transitions. At this time I don't want to enable third-party services for comments since it has become obvious in recent years that these providers invariably monetize information about their visitors and users.

Please use the links in the page footer to get in touch with me. I'm available for conversations on Keybase, Matrix, Mastodon or Twitter, as well as via email.