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 <g>). 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
the ExpressionDumper is going to produce this output (of course this is a very simple example, chosen for brevity):
Without further ado, here’s the download: ExpressionDumper.zip (5159 bytes)
Have fun!






You do know there’s an Expression Tree debugger visualizer ?
->
http://footheory.com/blogs/bennie/archive/2007/08/18/new-features-in-c-3-0-part-6-expression-trees.aspx
Comment by Frans Bouma — 6/9/2007 @ 12:33 pm - 1 year ago
Hey Frans -
No, actually I didn’t - seeing as it’s not even in beta 2 by default, I don’t think I’ll be the only one
Funny though, before I started doing this (a few weeks ago), I thought I’d read or heard something about such a tool, but I wasn’t able to find it again. Tried to ask people, but nobody knew… well, that’s how it goes.
In any case, having a stand-alone implementation still sounds like a good idea to me. It’s certainly easier to show in a presentation, with a big font in a console window, than clicking around in the debugger visualizer.
Comment by Oliver Sturm — 6/9/2007 @ 12:45 pm - 1 year ago
Yes, I think you’re right. I’ll first start with the shipped visualizer to see if I can use that to check whether the expression trees are shaped the way I think they are shaped (with the lack of serious documentation) but indeed a dumper is also good to have. Perhaps I’ll use yours as well and if necessary I’ll update it (and post you the code)
Thanks for sharing
Comment by Frans Bouma — 10/9/2007 @ 1:22 pm - 12 months ago