Skip to content

A .NET 3.5+ and .NET Standard 1.0 library and set of Debugger Visualizers which translate Expression Trees into readable C# source code

License

Notifications You must be signed in to change notification settings

weedkiller/ReadableExpressions

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ReadableExpressions

NuGet

ReadableExpressions is set of Debugger Visualizers and a NuGet-packaged extension method for readable, source-code versions of Expression Trees.

Debugger Visualizers

An installer for the Expression Debugger Visualizers can be downloaded from the Visual Studio Gallery.

The visualizer has both Light and Dark themes:

[Visualizer themes]

...and output can be customised using various options:

[Visualizer options]

ASP.NET Core 5 Known Issue

.NET 5 has a breaking change, which disables BinaryFormatter serialization by default. This causes issues with the ReadableExpressions visualizers (and elsewhere) when debugging ASP.NET Core apps as the VS debugger uses BinaryFormatter to serialize objects before sending them to the visualizer.

The solution is to enable the BinaryFormatter in Debug only by adding the following to your ASP.NET Core csproj:

<PropertyGroup>
  <TargetFramework>net5.0</TargetFramework>
  <EnableUnsafeBinaryFormatterSerialization Condition=" '$(Configuration)' == 'Debug' ">
    true
  </EnableUnsafeBinaryFormatterSerialization>
</PropertyGroup>

NuGet Package

The extension method is available in a NuGet package targeting .NETStandard 1.0+ and .NET 3.5+:

PM> Install-Package AgileObjects.ReadableExpressions

...and is used like so:

using AgileObjects.ReadableExpressions;

string readable = myExpression.ToReadableString();

...it also works on DynamicLanguageRuntime expressions.

Options

To include namespaces when outputting type names, use:

string readable = myExpression
    .ToReadableString(c => c.UseFullyQualifiedTypeNames);

To use full type names instead of var for local and inline-declared output parameter variables, use:

string readable = myExpression
    .ToReadableString(c => c.UseExplicitTypeNames);

To declare output parameter variables inline with the method where they are first used, use:

string readable = myExpression
    .ToReadableString(c => c.DeclareOutputParametersInline);

To maintain explicit generic arguments on method calls where they are implied, use:

string readable = myExpression
    .ToReadableString(c => c.UseExplicitGenericParameters);

To show implicitly-typed array type names, use:

string readable = myExpression
    .ToReadableString(c => c.ShowImplicitArrayTypes);

To show lambda parameter type names, use:

string readable = myExpression
    .ToReadableString(c => c.ShowLambdaParameterTypes);

To output a source code comment when a lambda is 'quoted', use:

string readable = myExpression
    .ToReadableString(c => c.ShowQuotedLambdaComments);

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 specify a custom string for code indenting, use:

string readable = myExpression
    .ToReadableString(c => c.IndentUsing("\t"));

About

A .NET 3.5+ and .NET Standard 1.0 library and set of Debugger Visualizers which translate Expression Trees into readable C# source code

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%