static bool CheckArgument(ExpressionParser parser, MethodCallExpression methE, bool left, out string hint)
        {
            int ix1 = left ? 0 : 1;
            int ix2 = left ? 1 : 0;

            if (typeof(Delegate).GetTypeInfo().IsAssignableFrom(methE.Arguments[ix1].Type.GetTypeInfo()))
            {
                object leftR;
                try
                {
                    leftR = parser.DynamicInvoke(Expression.Invoke(methE.Arguments[ix1]));
                }
                catch (InvalidOperationException) // delegate needs arguments
                {
                    hint = null;
                    return(false);
                }

                if (Equals(leftR, parser.DynamicInvoke(methE.Arguments[ix2])))
                {
                    hint = string.Format(", but would have been True if you had invoked '{0}'",
                                         NodeFormatter.PrettyPrint(parser.Parse(methE.Arguments[ix1])));
                    return(true);
                }
            }

            hint = null;
            return(false);
        }
Exemple #2
0
        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);
        }
Exemple #3
0
 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 async Task Tree(string path)
        {
            var root = await Hosting.GetItemsTreeAsync(path);

            var formatter = new NodeFormatter('=');

            Console.WriteLine(formatter.BuildNodes(root.Select(n => n.Name)));
        }
Exemple #6
0
        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);
 }
Exemple #8
0
        public static INodeFormatter CreateFormatter(string formatter, TypeReflectorOptions options)
        {
            INodeFormatter nformatter = Factories.Formatter.Create(formatter);
            NodeFormatter  f          = nformatter as NodeFormatter;

            if (f != null)
            {
                f.InvokeMethods = options.InvokeMethods;
            }

            return(nformatter);
        }
Exemple #9
0
        /// <summary>
        /// Adds the given node to the tree view.
        /// </summary>
        /// <param name="p_xndXmlNode">The node to add.</param>
        protected void AddNode(XmlNode p_xndXmlNode)
        {
            if (p_xndXmlNode.NodeType != XmlNodeType.Element)
            {
                return;
            }
            XmlTreeNode xtnNode = new XmlTreeNode(p_xndXmlNode);

            if (NodeFormatter != null)
            {
                NodeFormatter.FormatNode(xtnNode);
            }
            Nodes.Add(xtnNode);
            xtnNode.LoadChildren();
        }
Exemple #10
0
        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);
        }
Exemple #12
0
        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);
        }
Exemple #13
0
        public static string CreateSimpleFormatFor(LambdaExpression expression)
        {
            Node constantNode = NaturalExpressionParser.Parse(expression.Body);

            return(NodeFormatter.SimpleFormat(constantNode));
        }
Exemple #14
0
        public override string ToString()
        {
            var strings = NodeFormatter.Format(this);

            return(string.Join(Environment.NewLine, strings));
        }
 public void SetUp()
 {
     formatter = new NodeFormatter(' ', false);
 }
 public CredentialsFormatter()
 {
     formatter = new NodeFormatter(' ');
 }