So I like writing Expression tree API magic, but I am mortal and don’t find it that easy to do, and it normally takes me a while to do this. So I am up for any help that I can get.
I just learnt a neat little trick, which is that you can apply TypeDescriptor attributes at runtime, which is cool. This one thing allows us to use a fairly standard PropertyGrid to visualize Expression trees
For example here is a simple Winforms UI I crafted with a few Expressions to visualize and each one just gets set to the PropertyGrid SelectedObject when selected from the list
Ok its not perfect but it is good enough to help you out
Here is the relevant code from the simple Winforms UI
Expression<Func<string, string, int>> fun1 = (s1, s2) => s1.Length - s2.Length; TypeDescriptor.AddAttributes(typeof(Expression), new TypeConverterAttribute(typeof(ExpandableObjectConverter))); propertyGrid1.SelectedObject = fun1;
I’ve also written a set of debugger visualizers for Expressions which translate them into their source-code equivalent. Here! https://marketplace.visualstudio.com/items?itemName=vs-publisher-1232914.ReadableExpressionsVisualizers
Steve
That’s awesome work there dude. Very nice