Rendering complex lambda expressions as binary decision trees makes them easier to reason about for technical and non-technical users. Trace the flow through the decision tree followingTrue and False branches at each node until a leaf is reached. Note: The expression must be bound to a variable to support debugging tool tips and, therefore, debug visualizers. See the code below for an example. Usage: Hover over a lambda expression variable name ('expr' in the below examples) whilst deugging to display its value in a tool tip. Click on the magnifying glass icon in the tool tip to load the Expression Debug Visualizer.
Predicate expressions, as shown below used in a Linq Where clause, render to a binary decision tree terminating in a boolean value. C# Edit|Remove csharpExpression<Func<string, bool>> expr = s => s != null && (s == "Example" || s == "Demo");IEnumerable<string> result = strings.Where(expr); Expression<Func<string, bool>> expr = s => s != null && (s == "Example" || s == "Demo"); IEnumerable<string> result = strings.Where(expr); Ternary expressions, as shown below used in a Linq Select clause, render to a binary decision tree terminating in an instance of the return type defined by the expression. C# Edit|Remove csharpExpression<Func<int, string>> expr = i => i == 0 ? "Zero" : i < 0 ? "Negative" : i % 2 == 0 ? "Even" : "Odd";IEnumerable<string> result = integers.Select(expr); Expression<Func<int, string>> expr = i => i == 0 ? "Zero" : i < 0 ? "Negative" : i % 2 == 0 ? "Even" : "Odd"; IEnumerable<string> result = integers.Select(expr); ![]() Comments and suggestions are welcome. |