public void FormatTwoOperators() { string[] s = NodeFormatter.Format(new BinaryNode { Operator = "==", Value = "false", Left = new ConstantNode { Text = "31" }, Right = new BinaryNode { Operator = "*", Value = "30", Left = new ConstantNode { Text = "5" }, Right = new ConstantNode { Text = "6" } } }); string[] expected = { "31 == 5 * 6", " __ .", " | .", " | 30", " false" }; AssertLines(expected, s); }
public void FormatConstant() { string[] s = NodeFormatter.Format(new ConstantNode { Text = "5", Value = null }); AssertLines(new[] { "5" }, s); }
static string RenderExpression(LambdaExpression expression, params object [] parameterValues) { var parser = new ExpressionParser(expression.Body, expression.Parameters.ToArray(), parameterValues); Node constantNode = parser.Parse(); string[] lines = NodeFormatter.Format(constantNode); return(string.Join(CRLF, lines) + CRLF); }
public static Exception CreateException(LambdaExpression expression, string message) { Node constantNode = NaturalExpressionParser.Parse(expression.Body); string[] lines = NodeFormatter.Format(constantNode); string nl = Environment.NewLine; return(new Exception(message + ", expression was:" + nl + nl + String.Join(nl, lines))); }
public void PrintResults() { int x = 11; int y = 6; DateTime d = new DateTime(2010, 3, 1); Expression<Func<bool>> expression = () => x + 5 == d.Month * y; Node constantNode = NaturalExpressionParser.Parse(expression.Body); string[] strings = NodeFormatter.Format(constantNode); string s = string.Join(Environment.NewLine, strings); Console.Out.WriteLine(s); }
public void FormatInvocationNode() { string[] s = NodeFormatter.Format(new BinaryNode { Left = new InvocationNode { Arguments = new Node[] { new ConstantNode { Text = "a", Value = "3" }, new ConstantNode { Text = "x", Value = "2.423" } }, Expression = new ConstantNode { Text = "f", Value = "System.Func`3[System.Int32,System.Double,System.Double]" } }, Operator = "==", Right = new ConstantNode { Text = "314.4" }, Value = "False" }); string[] expected = { "f(a, x) == 314.4", ". . . __", ". . . |", "| . . |", "| | | False", "| | 2.423", "| 3", "System.Func`3[System.Int32,System.Double,System.Double]" }; AssertLines(expected, s); }
public void FormatOperator() { string[] s = NodeFormatter.Format(new BinaryNode { Operator = "==", Value = "false", Left = new ConstantNode { Text = "5" }, Right = new ConstantNode { Text = "6" } }); string[] expected = { "5 == 6", " false" }; AssertLines(expected, s); }
public void FormatNewAnonymousNode() { var s = NodeFormatter.Format(new NewAnonymousTypeNode { Parameters = new[] { new MemberAssignmentNode { MemberName = "Value", Value = new ConstantNode { Text = "x", Value = "1" } }, new MemberAssignmentNode { MemberName = "x", Value = new ConstantNode { Text = "x", Value = "1" } } }.ToList(), Value = "{ Value = 1, x = 1 }" }); var expected = new[] { @"new {Value = x, x}", @"\_ _/ . .", @" | . .", @" | | 1", @" | 1", @" { Value = 1, x = 1 }", }; AssertLines(expected, s); }
public override string ToString() { var strings = NodeFormatter.Format(this); return(string.Join(Environment.NewLine, strings)); }