![]() |
VOOZH | about |
dotnet add package ExpressionTreeToString --version 3.4.71
NuGet\Install-Package ExpressionTreeToString -Version 3.4.71
<PackageReference Include="ExpressionTreeToString" Version="3.4.71" />
<PackageVersion Include="ExpressionTreeToString" Version="3.4.71" />Directory.Packages.props
<PackageReference Include="ExpressionTreeToString" />Project file
paket add ExpressionTreeToString --version 3.4.71
#r "nuget: ExpressionTreeToString, 3.4.71"
#:package ExpressionTreeToString@3.4.71
#addin nuget:?package=ExpressionTreeToString&version=3.4.71Install as a Cake Addin
#tool nuget:?package=ExpressionTreeToString&version=3.4.71Install as a Cake Tool
👁 AppVeyor build status
👁 Tests
👁 NuGet Status
Test objects: 👁 NuGet TestObjects Status
👁 Targets .NET Standard 2.0 | .NET 5.0 | Framework 4.5.2
Provides a ToString extension method which returns a string representation of an expression tree (an object inheriting from System.Linq.Expressions.Expression).
Expression<Func<bool>> expr = () => true;
Console.WriteLine(expr.ToString("C#"));
// prints: () => true
Console.WriteLine(expr.ToString("Visual Basic"));
// prints: Function() True
Console.WriteLine(expr.ToString("Factory methods", "C#"));
// prints:
/*
// using static System.Linq.Expressions.Expression
Lambda(
Constant(true)
)
*/
Console.WriteLine(expr.ToString("Object notation", "C#"));
// prints:
/*
new Expression<Func<bool>> {
NodeType = ExpressionType.Lambda,
Type = typeof(Func<bool>),
Body = new ConstantExpression {
Type = typeof(bool),
Value = true
},
ReturnType = typeof(bool)
}
*/
Console.WriteLine(expr.ToString("Object notation", "Visual Basic"));
// prints:
/*
New Expression(Of Func(Of Boolean)) With {
.NodeType = ExpressionType.Lambda,
.Type = GetType(Func(Of Boolean)),
.Body = New ConstantExpression With {
.Type = GetType(Boolean),
.Value = True
},
.ReturnType = GetType(Boolean)
}
*/
Console.WriteLine(expr.ToString("Textual tree"));
// prints:
/*
Lambda (Func<bool>)
Body - Constant (bool) = True
*/
var b = true;
Expression<Func<int>> expr1 = () => b ? 1 : 0;
Console.WriteLine(expr1.ToString("ToString"));
// prints:
/*
() => IIF(value(_tests.Program+<>c__DisplayClass0_0).b, 1, 0)
*/
Console.WriteLine(expr1.ToString("DebugView"));
// prints:
/*
.Lambda #Lambda1<System.Func`1[System.Int32]>() {
.If (
.Constant<_tests.Program+<>c__DisplayClass0_0>(_tests.Program+<>c__DisplayClass0_0).b
) {
1
} .Else {
0
}
}
*/
Expression<Func<Person, bool>> filter = p => p => p.LastName == "A" || p.FirstName == "B" || p.DOB == DateTime.MinValue || p.LastName == "C" || p.FirstName == "D";
Console.WriteLine(filter.ToString("Dynamic LINQ", "C#"));
// prints:
/*
"LastName in (\"A\", \"C\") || FirstName in (\"B\", \"D\") || DOB == DateTime.MinValue"
*/
Features:
Multiple writers:
For C# and VB pseudo-code representations:
Extension methods are rendered as instance methods
Expression<Func<int, int>> expr = x => Enumerable.Range(1, x).Select(y => x * y).Count();
Console.WriteLine(expr.ToString("C#"));
// prints: (int x) => Enumerable.Range(1, x).Select((int y) => x * y).Count()
Closed-over variables are rendered as simple identifiers (instead of member access on the hidden compiler-generated class)
var i = 7;
var j = 8;
Expression<Func<int>> expr = () => i + j;
Console.WriteLine(expr.ToString("C#"));
// prints: () => i + j
Calls to String.Concat and String.Format are mapped to the + operator and string interpolation, respectively (where possible):
var name = "World";
Expression<Func<string>> expr = () => string.Format("Hello, {0}!", name);
Console.WriteLine(expr.ToString("C#"));
// prints: () => $"Hello, {name}!"
Unnecessary conversions are not rendered:
Expression<Func<IEnumerable<char>>> expr = () => (IEnumerable<char>)"abcd";
Console.WriteLine(expr.ToString("C#"));
// prints: () => "abcd"
Comparisons against an enum or char are rendered properly, not as comparison to int-converted value:
var dow = DayOfWeek.Sunday;
Expression<Func<bool>> expr = () => DateTime.Today.DayOfWeek == dow;
Console.WriteLine(expr.ToString("Textual tree", "C#"));
// prints:
/*
Lambda (Func<bool>)
· Body - Equal (bool) = false
· Left - Convert (int) = 3
· Operand - MemberAccess (DayOfWeek) DayOfWeek = DayOfWeek.Wednesday
· Expression - MemberAccess (DateTime) DateTime.Today = 30/09/2020 12:00:00 am
· Right - Convert (int) = 0
· Operand - MemberAccess (DayOfWeek) dow = DayOfWeek.Sunday
· Expression - Constant (<closure>) = #<closure>
*/
Console.WriteLine(expr.ToString("C#"));
// prints: () => DateTime.Today.DayOfWeek == dow
Each representation (including the ToString and DebugView renderers) can return the start and length of the substring corresponding to any of the paths of the tree's nodes, which can be used to find the substring corresponding to a given node in the tree:
var s = expr.ToString("C#", out var pathSpans);
Console.WriteLine(s);
// prints: (Person p) => p.DOB.DayOfWeek == DayOfWeek.Tuesday
(int start, int length) = pathSpans["Body.Left.Operand"];
Console.WriteLine(s.Substring(start, length));
// prints: p.DOB.DayOfWeek
Type names are rendered using language syntax and keywords, instead of the Type.Name property; e.g. List<string> or List(Of Date) instead of List`1
Supports the full range of types in System.Linq.Expressions, including .NET 4 expression types, and DynamicExpression
Extensibility -- allows creating custom renderers, or inheriting from existing renderers, to handle your own Expression-derived types
For more information, see the wiki.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 is compatible. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net452 net452 is compatible. net46 net46 was computed. net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on ExpressionTreeToString:
| Package | Downloads |
|---|---|
|
NBomber
Modern and flexible load testing framework for Pull and Push scenarios, designed to test any system regardless a protocol (HTTP/WebSockets/AMQP etc) or a semantic model (Pull/Push). |
|
|
NCPC.Utils
Usefull methods of common use |
|
|
RaaLabs.Edge
Package Description |
|
|
ExpressionTreeVisualizer.UI
UI pieces for displaying expression trees |
|
|
NiuX.Common
csharp common, utils, helpers, tools etc. |
Showing the top 3 popular GitHub repositories that depend on ExpressionTreeToString:
| Repository | Stars |
|---|---|
| yangzhongke/NETBookMaterials | |
|
zspitz/ExpressionTreeVisualizer
Debugging visualizer for expression trees
|
|
|
NeVeSpl/RevitDBExplorer
Interactive Revit database exploration tool to view and edit BIM element parameters, properties and relationships.
|
| Version | Downloads | Last Updated |
|---|---|---|
| 3.4.71 | 1,377,460 | 2/25/2022 |
| 3.4.70 | 4,589 | 12/23/2021 |
| 3.4.68 | 1,289 | 12/14/2021 |
| 3.4.67 | 544 | 12/14/2021 |
| 3.4.65 | 26,473 | 7/14/2021 |
| 3.4.64 | 625 | 7/14/2021 |
| 3.4.63 | 51,979 | 7/5/2021 |
| 3.4.62 | 1,017 | 6/29/2021 |
| 3.4.61 | 802 | 6/23/2021 |
| 3.4.60 | 633 | 6/23/2021 |
| 3.3.59 | 653 | 6/17/2021 |
| 3.3.58 | 701 | 6/7/2021 |
| 3.3.57 | 607 | 6/6/2021 |
| 3.3.56 | 668 | 5/31/2021 |
| 3.2.54 | 42,766 | 1/16/2021 |
| 3.2.53 | 7,239 | 12/6/2020 |
| 3.2.52 | 793 | 12/5/2020 |
| 3.2.51 | 788 | 12/5/2020 |
| 3.2.50 | 784 | 12/5/2020 |
| 3.2.49 | 695 | 12/5/2020 |
Non-statement expression support is complete, escaped string literals, exceptions written into source