Generates valid, readable C# source code from .NET Expression Trees, with enhanced assertion failure messages.
ExpressionToCode is a .NET library that converts System.Linq.Expressions.Expression objects into readable C# source code. It solves the problem of debugging complex expression trees by providing human-readable representations and detailed assertion failure messages. The library is especially useful for understanding expression evaluation in unit tests and debugging scenarios.
C# developers working with expression trees, particularly those using unit testing frameworks like NUnit or xUnit.NET who need better debugging visibility. Library authors dealing with complex expression manipulation will also find it valuable.
Developers choose ExpressionToCode because it generates valid, compilable C# code from expression trees with high accuracy, unlike alternatives that may produce invalid syntax. Its Power Assert feature provides unparalleled debugging detail by showing subexpression values when assertions fail.
Generates valid, readable C# from an Expression Tree.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Converts expression trees to valid, compilable C# code with proper operator precedence and formatting, as shown in examples where complex lambdas are accurately rendered without syntax errors.
Provides detailed assertion failure messages with subexpression values, inspired by Groovy's Power Assert, making it easier to pinpoint issues in unit tests, as demonstrated with Enumerable.Range failures.
Supports a wide range of C# features including static members, indexers, object initializers, anonymous types, and nested lambdas, ensuring high readability for diverse expression trees.
Offers multiple rendering options like values-on-stalks annotations, allowing developers to choose compact or detailed visualization based on testing needs, as shown in the configuration examples.
The library does not support converting LINQ query syntax expressions to code, as admitted in the README under 'Not implemented (yet?)', limiting its utility for projects using query expressions extensively.
Introspecting expression trees and computing subexpression values can add significant overhead, which might be problematic in large-scale or performance-critical unit tests, despite default limits on sequence lengths.
Requires .NET 4.5.2 or .NET Standard 1.6, which may not be compatible with all development environments, especially older .NET projects or those targeting different frameworks.