ReadableExpressions is an extension method for the Expression class and set of Debugger Visualizers to produce readable, source-code string versions of Expression Trees. It targets .NETStandard 1.0+ and .NET 3.5+.
The extension method (in the namespace AgileObjects.ReadableExpressions
) is used like so:
string readable = myExpression.ToReadableString();
...it also works on DynamicLanguageRuntime expressions.
To maintain explicit generic arguments on method calls where they are implied, use:
string readable = myExpression
.ToReadableString(c => c.UseExplicitGenericParameters);
To include namespaces when outputting Type names, use:
string readable = myExpression
.ToReadableString(c => c.UseFullyQualifiedTypeNames);
To define a custom factory for naming anonymous types, use:
string readable = myExpression
.ToReadableString(c => c.NameAnonymousTypesUsing(
anonType => GetAnonTypeName(anonType)));
To define a custom factory for translating ConstantExpression values, use:
string readable = myExpression
.ToReadableString(c => c.TranslateConstantsUsing(
(constantType, constantValue) => GetConstantValue(constantType, constantValue)));
To output a source code comment when a lambda is 'quoted', use:
string readable = myExpression
.ToReadableString(c => c.ShowQuotedLambdaComments);
An installer for a set of Debugger Visualizers which use the extension method for Expressions can be downloaded from the Visual Studio Gallery.
You can download and install using the NuGet package, or clone the repository on GitHub.