Beispiel #1
0
        public void ParseMemberAccess()
        {
            DateTime d = new DateTime(2010, 12, 25);
            Expression<Func<int>> f = () => d.Day;
            MemberAccessNode node = (MemberAccessNode)ExpressionParser.Parse(f.Body);

            MemberAccessNode expected = new MemberAccessNode
                                        {
                                            Container = new ConstantNode { Text = "d", Value = d.ToString() },
                                            MemberName = "Day",
                                            MemberValue = "25"
                                        };

            Assert.AreEqual(expected, node);
        }
 public void ParseNewAnonymousType()
 {
     int x = 1;
     Expression<Func<int>> f = () => new { Value = x, x }.Value;
     var p = new ExpressionParser(f.Body);
     var node = p.Parse();
     var expected = new MemberAccessNode
     {
         Container = 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 }"
         },
         MemberName = "Value",
         MemberValue = "1"
     };
     Assert.AreEqual(expected, node);
 }