public void GenericArrayAsCastExpression()
 {
     ParseUtilCSharp.AssertExpression(
         "o as List<string>[]",
         new AsExpression {
         Type = new ComposedType {
             BaseType = new SimpleType("List")
             {
                 TypeArguments = { new PrimitiveType("string") }
             },
             ArraySpecifiers = { new ArraySpecifier(1) }
         },
         Expression = new IdentifierExpression("o")
     });
 }
Example #2
0
        public void MultipleGenerators()
        {
            ParseUtilCSharp.AssertExpression(
                @"
from c in customers
where c.City == ""London""
from o in c.Orders
where o.OrderDate.Year == 2005
select new { c.Name, o.OrderID, o.Total }",
                new QueryExpression
            {
                Clauses =
                {
                    new QueryFromClause   {
                        Identifier = "c",
                        Expression = new IdentifierExpression("customers")
                    },
                    new QueryWhereClause  {
                        Condition = new BinaryOperatorExpression{
                            Left     = new IdentifierExpression("c").Member("City"),
                            Operator = BinaryOperatorType.Equality,
                            Right    = new PrimitiveExpression("London")
                        }
                    },
                    new QueryFromClause   {
                        Identifier = "o",
                        Expression = new IdentifierExpression("c").Member("Orders")
                    },
                    new QueryWhereClause  {
                        Condition = new BinaryOperatorExpression{
                            Left     = new IdentifierExpression("o").Member("OrderDate").Member("Year"),
                            Operator = BinaryOperatorType.Equality,
                            Right    = new PrimitiveExpression(2005)
                        }
                    },
                    new QuerySelectClause {
                        Expression = new AnonymousTypeCreateExpression{
                            Initializers =
                            {
                                new IdentifierExpression("c").Member("Name"),
                                new IdentifierExpression("o").Member("OrderID"),
                                new IdentifierExpression("o").Member("Total")
                            }
                        }
                    }
                }
            });
        }
 public void GenericDefaultValue()
 {
     ParseUtilCSharp.AssertExpression(
         "default(MyNamespace.N1.MyType<string>)",
         new DefaultValueExpression
     {
         Type = new MemberType {
             Target = new MemberType {
                 Target     = new SimpleType("MyNamespace"),
                 MemberName = "N1"
             },
             MemberName    = "MyType",
             TypeArguments = { new PrimitiveType("string") }
         }
     });
 }
Example #4
0
 public void ObjectInitializerWithTrailingComma()
 {
     ParseUtilCSharp.AssertExpression(
         "new Point() { X = 0, Y = 1, }",
         new ObjectCreateExpression
     {
         Type        = new SimpleType("Point"),
         Initializer = new ArrayInitializerExpression {
             Elements =
             {
                 new NamedExpression("X", new PrimitiveExpression(0)),
                 new NamedExpression("Y", new PrimitiveExpression(1))
             }
         }
     });
 }
 public void ArrayWithImplicitSize()
 {
     ParseUtilCSharp.AssertExpression(
         "new int[] { 1 }",
         new ArrayCreateExpression
     {
         Type = new PrimitiveType("int"),
         AdditionalArraySpecifiers =
         {
             new ArraySpecifier(0)
         },
         Initializer = new ArrayInitializerExpression {
             Elements = { new PrimitiveExpression(1) }
         }
     });
 }
 public void ImplicitlyTypedArrayCreateExpression()
 {
     ParseUtilCSharp.AssertExpression(
         "new[] { 1, 10, 100, 1000 }",
         new ArrayCreateExpression {
         Initializer = new ArrayInitializerExpression {
             Elements =
             {
                 new PrimitiveExpression(1),
                 new PrimitiveExpression(10),
                 new PrimitiveExpression(100),
                 new PrimitiveExpression(1000)
             }
         }
     });
 }
 public void ExplicitlyTypedWithRefParameter()
 {
     ParseUtilCSharp.AssertExpression(
         "(ref int i) => i = 1",
         new LambdaExpression {
         Parameters =
         {
             new ParameterDeclaration {
                 ParameterModifier = ParameterModifier.Ref,
                 Type = new PrimitiveType("int"),
                 Name = "x"
             }
         },
         Body = new AssignmentExpression(new IdentifierExpression("i"), new PrimitiveExpression(1))
     });
 }
Example #8
0
 public void ArglistCall()
 {
     ParseUtilCSharp.AssertExpression(
         "GetArgCount(__arglist(a, b, c))",
         new IdentifierExpression("GetArgCount").Invoke(
             new UndocumentedExpression
     {
         UndocumentedExpressionType = UndocumentedExpressionType.ArgList,
         Arguments =
         {
             new IdentifierExpression("a"),
             new IdentifierExpression("b"),
             new IdentifierExpression("c")
         }
     }));
 }
 public void ImplicitlyTypedStatementBodyWithoutParenthesis()
 {
     ParseUtilCSharp.AssertExpression(
         "x => { return x + 1; }",
         new LambdaExpression {
         Parameters = { new ParameterDeclaration {
                            Name = "x"
                        } },
         Body = new BlockStatement {
             new ReturnStatement {
                 Expression = new BinaryOperatorExpression(
                     new IdentifierExpression("x"), BinaryOperatorType.Add, new PrimitiveExpression(1))
             }
         }
     });
 }
 public void ExplicitlyTypedStatementBody()
 {
     ParseUtilCSharp.AssertExpression(
         "(int x) => { return x + 1; }",
         new LambdaExpression {
         Parameters = { new ParameterDeclaration {
                            Type = new PrimitiveType("int"), Name = "x"
                        } },
         Body = new BlockStatement {
             new ReturnStatement {
                 Expression = new BinaryOperatorExpression(
                     new IdentifierExpression("x"), BinaryOperatorType.Add, new PrimitiveExpression(1))
             }
         }
     });
 }
Example #11
0
 public void CollectionInitializer()
 {
     ParseUtilCSharp.AssertExpression(
         "new List<int> { 0, 1, 2 }",
         new ObjectCreateExpression {
         Type        = new SimpleType("List", new PrimitiveType("int")),
         Initializer = new ArrayInitializerExpression {
             Elements =
             {
                 new ArrayInitializerExpression(new PrimitiveExpression(0)),
                 new ArrayInitializerExpression(new PrimitiveExpression(1)),
                 new ArrayInitializerExpression(new PrimitiveExpression(2))
             }
         }
     });
 }
Example #12
0
 public void GenericInvocation2ExpressionTest()
 {
     ParseUtilCSharp.AssertExpression(
         "myMethod<T,bool>()",
         new InvocationExpression {
         Target = new IdentifierExpression {
             Identifier    = "myMethod",
             TypeArguments =
             {
                 new SimpleType("T"),
                 new PrimitiveType("bool")
             }
         }
     }
         );
 }
 public void LambdaExpressionContainingConditionalExpression()
 {
     ParseUtilCSharp.AssertExpression(
         "rr => rr != null ? rr.ResolvedType : null",
         new LambdaExpression {
         Parameters = { new ParameterDeclaration {
                            Name = "rr"
                        } },
         Body = new ConditionalExpression {
             Condition = new BinaryOperatorExpression(
                 new IdentifierExpression("rr"), BinaryOperatorType.InEquality, new NullReferenceExpression()),
             TrueExpression  = new IdentifierExpression("rr").Member("ResolvedType"),
             FalseExpression = new NullReferenceExpression()
         }
     });
 }
Example #14
0
 public void SetRefValue()
 {
     ParseUtilCSharp.AssertExpression(
         "__refvalue(tr, object) = o",
         new AssignmentExpression(
             new UndocumentedExpression
     {
         UndocumentedExpressionType = UndocumentedExpressionType.RefValue,
         Arguments =
         {
             new IdentifierExpression("tr"),
             new TypeReferenceExpression(new PrimitiveType("object"))
         }
     },
             new IdentifierExpression("o")));
 }
Example #15
0
 public void AssignmentInArrayInitializer()
 {
     ParseUtilCSharp.AssertExpression(
         "new [] { a = 10 }",
         new ArrayCreateExpression {
         AdditionalArraySpecifiers =
         {
             new ArraySpecifier(0)
         },
         Initializer = new ArrayInitializerExpression {
             Elements =
             {
                 new AssignmentExpression(new IdentifierExpression("a"), new PrimitiveExpression(10))
             }
         }
     });
 }
Example #16
0
 public void AmbiguousGrammarNotAGenericMethodCall()
 {
     ParseUtilCSharp.AssertExpression(
         "F<A>+y",
         new BinaryOperatorExpression {
         Left = new BinaryOperatorExpression {
             Left     = new IdentifierExpression("F"),
             Operator = BinaryOperatorType.LessThan,
             Right    = new IdentifierExpression("A")
         },
         Operator = BinaryOperatorType.GreaterThan,
         Right    = new UnaryOperatorExpression {
             Operator   = UnaryOperatorType.Plus,
             Expression = new IdentifierExpression("y")
         }
     });
 }
Example #17
0
 public void InvocationWithNamedArgument()
 {
     ParseUtilCSharp.AssertExpression(
         "a(arg: ref v)",
         new InvocationExpression {
         Target    = new IdentifierExpression("a"),
         Arguments =
         {
             new NamedArgumentExpression {
                 Name       = "arg",
                 Expression = new DirectionExpression{
                     FieldDirection = FieldDirection.Ref,
                     Expression     = new IdentifierExpression("v")
                 }
             }
         }
     });
 }
Example #18
0
 public void NestedGenericTypeOfExpressionTest()
 {
     ParseUtilCSharp.AssertExpression(
         "typeof(MyType<string>.InnerClass<int>.InnerInnerClass)",
         new TypeOfExpression {
         Type = new MemberType {
             Target = new MemberType {
                 Target = new SimpleType("MyType")
                 {
                     TypeArguments = { new PrimitiveType("string") }
                 },
                 MemberName    = "InnerClass",
                 TypeArguments = { new PrimitiveType("int") }
             },
             MemberName = "InnerInnerClass"
         }
     });
 }
Example #19
0
 public void ExpressionWithType2()
 {
     ParseUtilCSharp.AssertExpression(
         "from int c in customers select c",
         new QueryExpression {
         Clauses =
         {
             new QueryFromClause   {
                 Type       = new PrimitiveType("int"),
                 Identifier = "c",
                 Expression = new IdentifierExpression("customers")
             },
             new QuerySelectClause {
                 Expression = new IdentifierExpression("c")
             }
         }
     });
 }
Example #20
0
 public void ExpressionWithType1()
 {
     ParseUtilCSharp.AssertExpression(
         "from Customer c in customers select c",
         new QueryExpression {
         Clauses =
         {
             new QueryFromClause   {
                 Type       = new SimpleType("Customer"),
                 Identifier = "c",
                 Expression = new IdentifierExpression("customers")
             },
             new QuerySelectClause {
                 Expression = new IdentifierExpression("c")
             }
         }
     });
 }
Example #21
0
 public void QueryWithGroupBy()
 {
     ParseUtilCSharp.AssertExpression(
         "from a in b group c by d",
         new QueryExpression {
         Clauses =
         {
             new QueryFromClause  {
                 Identifier = "a",
                 Expression = new IdentifierExpression("b")
             },
             new QueryGroupClause {
                 Projection = new IdentifierExpression("c"),
                 Key        = new IdentifierExpression("d")
             }
         }
     });
 }
Example #22
0
 public void FullQualifiedDefaultValue()
 {
     ParseUtilCSharp.AssertExpression(
         "default(global::MyNamespace.N1.MyType)",
         new DefaultValueExpression {
         Type = new MemberType {
             Target = new MemberType {
                 Target = new MemberType {
                     Target        = new SimpleType("global"),
                     IsDoubleColon = true,
                     MemberName    = "MyNamespace"
                 },
                 MemberName = "N1"
             },
             MemberName = "MyType"
         }
     });
 }
Example #23
0
 public void AmbiguousGrammarGenericMethodCall()
 {
     ParseUtilCSharp.AssertExpression(
         "F(G<A,B>(7))",
         new InvocationExpression {
         Target    = new IdentifierExpression("F"),
         Arguments =
         {
             new InvocationExpression {
                 Target = new IdentifierExpression{
                     Identifier    = "G",
                     TypeArguments =  { new SimpleType("A"),new SimpleType("B") }
                 },
                 Arguments =          { new PrimitiveExpression(7) }
             }
         }
     });
 }
        public void GlobalFullNamespaceGenericFieldReferenceExpressionTest()
        {
            var target = new MemberType {
                Target        = new SimpleType("global"),
                IsDoubleColon = true,
                MemberName    = "Namespace"
            }.Member("Subnamespace").Member("SomeClass");

            target.AddChild(new PrimitiveType("string"), Roles.TypeArgument);

            ParseUtilCSharp.AssertExpression(
                "global::Namespace.Subnamespace.SomeClass<string>.myField",
                new MemberReferenceExpression {
                Target     = target,
                MemberName = "myField"
            }
                );
        }
Example #25
0
 public void DictionaryInitializer()
 {
     ParseUtilCSharp.AssertExpression(
         "new Dictionary<string, int> { { \"a\", 0 }, { \"b\", 1 } }",
         new ObjectCreateExpression {
         Type        = new SimpleType("Dictionary", new PrimitiveType("string"), new PrimitiveType("int")),
         Initializer = new ArrayInitializerExpression {
             Elements =
             {
                 new ArrayInitializerExpression {
                     Elements =                 { new PrimitiveExpression("a"), new PrimitiveExpression(0) }
                 },
                 new ArrayInitializerExpression {
                     Elements =                 { new PrimitiveExpression("b"), new PrimitiveExpression(1) }
                 }
             }
         }
     });
 }
Example #26
0
 public void AssignmentInCollectionInitializer()
 {
     ParseUtilCSharp.AssertExpression(
         @"new List<int> { { a = 1 } }",
         new ObjectCreateExpression {
         Type        = new SimpleType("List", new PrimitiveType("int")),
         Initializer = new ArrayInitializerExpression {
             Elements =
             {
                 new ArrayInitializerExpression {
                     Elements =
                     {
                         new AssignmentExpression(new IdentifierExpression("a"), new PrimitiveExpression(1))
                     }
                 }
             }
         }
     });
 }
Example #27
0
 public void MultipleQueryContinuation()
 {
     ParseUtilCSharp.AssertExpression(
         "from a in b select c into d select e into f select g",
         new QueryExpression
     {
         Clauses =
         {
             new QueryContinuationClause                   {
                 PrecedingQuery = new QueryExpression      {
                     Clauses =
                     {
                         new QueryContinuationClause       {
                             PrecedingQuery = new QueryExpression{
                                 Clauses =
                                 {
                                     new QueryFromClause   {
                                         Identifier = "a",
                                         Expression = new IdentifierExpression("b")
                                     },
                                     new QuerySelectClause {
                                         Expression = new IdentifierExpression("c")
                                     }
                                 }
                             },
                             Identifier = "d"
                         },
                         new QuerySelectClause             {
                             Expression = new IdentifierExpression("e")
                         }
                     }
                 },
                 Identifier = "f"
             },
             new QuerySelectClause                         {
                 Expression = new IdentifierExpression("g")
             }
         }
     });
 }
Example #28
0
 public void NestedObjectInitializer()
 {
     ParseUtilCSharp.AssertExpression(
         "new Rectangle { P1 = new Point { X = 0, Y = 1 }, P2 = new Point { X = 2, Y = 3 } }",
         new ObjectCreateExpression
     {
         Type        = new SimpleType("Rectangle"),
         Initializer = new ArrayInitializerExpression {
             Elements =
             {
                 new NamedExpression(
                     "P1",
                     new ObjectCreateExpression {
                     Type        = new SimpleType("Point"),
                     Initializer = new ArrayInitializerExpression {
                         Elements =
                         {
                             new NamedExpression("X", new PrimitiveExpression(0)),
                             new NamedExpression("Y", new PrimitiveExpression(1))
                         }
                     }
                 }),
                 new NamedExpression(
                     "P2",
                     new ObjectCreateExpression {
                     Type        = new SimpleType("Point"),
                     Initializer = new ArrayInitializerExpression {
                         Elements =
                         {
                             new NamedExpression("X", new PrimitiveExpression(2)),
                             new NamedExpression("Y", new PrimitiveExpression(3))
                         }
                     }
                 })
             }
         }
     });
 }
Example #29
0
 public void QueryWithJoin()
 {
     ParseUtilCSharp.AssertExpression(
         "from a in b join c in d on e equals f select g",
         new QueryExpression {
         Clauses =
         {
             new QueryFromClause   {
                 Identifier = "a",
                 Expression = new IdentifierExpression("b")
             },
             new QueryJoinClause   {
                 JoinIdentifier   = "c",
                 InExpression     = new IdentifierExpression("d"),
                 OnExpression     = new IdentifierExpression("e"),
                 EqualsExpression = new IdentifierExpression("f")
             },
             new QuerySelectClause {
                 Expression = new IdentifierExpression("g")
             }
         }
     });
 }
Example #30
0
 public void ExpressionWithOrderByWithTwoOrderByDecendings()
 {
     ParseUtilCSharp.AssertExpression(
         "from c in customers orderby c.Name descending orderby c.Address descending select c",
         new QueryExpression
     {
         Clauses =
         {
             new QueryFromClause       {
                 Identifier = "c",
                 Expression = new IdentifierExpression("customers")
             },
             new QueryOrderClause      {
                 Orderings =
                 {
                     new QueryOrdering {
                         Expression = new IdentifierExpression("c").Member("Name"),
                         Direction  = QueryOrderingDirection.Descending
                     }
                 }
             },
             new QueryOrderClause      {
                 Orderings =
                 {
                     new QueryOrdering {
                         Expression = new IdentifierExpression("c").Member("Address"),
                         Direction  = QueryOrderingDirection.Descending
                     }
                 }
             },
             new QuerySelectClause     {
                 Expression = new IdentifierExpression("c")
             }
         }
     });
 }