Example #1
0
        public void ArglistAccess()
        {
            ParseUtilCSharp.AssertTypeMember(
                @"public static int GetArgCount(__arglist)
				{
					ArgIterator argIterator = new ArgIterator(__arglist);
					return argIterator.GetRemainingCount();
				}"                ,
                new MethodDeclaration {
                Modifiers  = Modifiers.Public | Modifiers.Static,
                ReturnType = new PrimitiveType("int"),
                Name       = "GetArgCount",
                Parameters =
                {
                    new ParameterDeclaration(AstType.Null, "__arglist")
                },
                Body = new BlockStatement {
                    new VariableDeclarationStatement(
                        new SimpleType("ArgIterator"),
                        "argIterator",
                        new ObjectCreateExpression(
                            new SimpleType("ArgIterator"),
                            new UndocumentedExpression {
                        UndocumentedExpressionType = UndocumentedExpressionType.ArgListAccess
                    })
                        ),
                    new ReturnStatement(new IdentifierExpression("argIterator").Invoke("GetRemainingCount"))
                }
            });
        }
 public void EventImplementingGenericInterfaceDeclarationTest()
 {
     ParseUtilCSharp.AssertTypeMember(
         "event EventHandler MyInterface<string>.MyEvent { add { } [Attr] remove {} }",
         new CustomEventDeclaration {
         ReturnType = new SimpleType("EventHandler"),
         PrivateImplementationType = new SimpleType {
             Identifier    = "MyInterface",
             TypeArguments = { new PrimitiveType("string") }
         },
         Name        = "MyEvent",
         AddAccessor = new Accessor {
             Body = new BlockStatement()
         },
         RemoveAccessor = new Accessor {
             Attributes =
             {
                 new AttributeSection  {
                     Attributes =
                     {
                         new Attribute {
                             Type = new SimpleType("Attr")
                         }
                     }
                 }
             },
             Body = new BlockStatement()
         }
     });
 }
Example #3
0
 public void IndexerImplementingGenericInterfaceTest()
 {
     ParseUtilCSharp.AssertTypeMember(
         "int MyInterface<string>.this[int a, string b] { get { } [Attr] set { } }",
         new IndexerDeclaration {
         ReturnType = new PrimitiveType("int"),
         PrivateImplementationType = new SimpleType {
             Identifier    = "MyInterface",
             TypeArguments = { new PrimitiveType("string") }
         },
         Name       = "this",
         Parameters =
         {
             new ParameterDeclaration(new PrimitiveType("int"),    "a"),
             new ParameterDeclaration(new PrimitiveType("string"), "b")
         },
         Getter = new Accessor {
             Body = new BlockStatement()
         },
         Setter = new Accessor {
             Attributes = { new AttributeSection(new Attribute {
                     Type = new SimpleType("Attr")
                 }) },
             Body = new BlockStatement()
         }
     });
 }
Example #4
0
 public void GenericMethodWithMultipleConstraints()
 {
     ParseUtilCSharp.AssertTypeMember(
         "void MyMethod<A, B>() where A : IA where B : IB {} ",
         new MethodDeclaration {
         ReturnType     = new PrimitiveType("void"),
         Name           = "MyMethod",
         TypeParameters =
         {
             new TypeParameterDeclaration {
                 Name = "A"
             },
             new TypeParameterDeclaration {
                 Name = "B"
             }
         },
         Constraints =
         {
             new Constraint {
                 TypeParameter = new SimpleType("A"),
                 BaseTypes     = { new SimpleType("IA") }
             },
             new Constraint {
                 TypeParameter = new SimpleType("B"),
                 BaseTypes     = { new SimpleType("IB") }
             }
         }
     });
 }
Example #5
0
 public void AttributeWithNamedArguments()
 {
     ParseUtilCSharp.AssertTypeMember(
         @"[A(0, a:1, b=2)] class Test {}",
         new TypeDeclaration {
         ClassType  = ClassType.Class,
         Name       = "Test",
         Attributes =
         {
             new AttributeSection  {
                 Attributes =
                 {
                     new Attribute {
                         Type      = new SimpleType("A"),
                         Arguments =
                         {
                             new PrimitiveExpression(0),
                             new NamedArgumentExpression("a",new PrimitiveExpression(1)),
                             new NamedExpression("b",        new PrimitiveExpression(2))
                         }
                     }
                 }
             }
         }
     });
 }
 public void SimpleFieldDeclarationTest()
 {
     ParseUtilCSharp.AssertTypeMember(
         "int[,,,] myField;",
         new FieldDeclaration {
         ReturnType = new PrimitiveType("int").MakeArrayType(4),
         Variables  = { new VariableInitializer("myField") }
     });
 }
Example #7
0
 public void VoidMethodImplementingInterfaceTest()
 {
     ParseUtilCSharp.AssertTypeMember(
         "void MyInterface.MyMethod() {} ",
         new MethodDeclaration {
         ReturnType = new PrimitiveType("void"),
         PrivateImplementationType = new SimpleType("MyInterface"),
         Name = "MyMethod",
         Body = new BlockStatement()
     });
 }
Example #8
0
 public void AsyncMethod()
 {
     ParseUtilCSharp.AssertTypeMember(
         "async void MyMethod() {}",
         new MethodDeclaration {
         Modifiers  = Modifiers.Async,
         ReturnType = new PrimitiveType("void"),
         Name       = "MyMethod",
         Body       = new BlockStatement()
     });
 }
 public void MultipleFieldDeclarationTest()
 {
     ParseUtilCSharp.AssertTypeMember(
         "int a = 1, b = 2;",
         new FieldDeclaration {
         ReturnType = new PrimitiveType("int"),
         Variables  =
         {
             new VariableInitializer("a", new PrimitiveExpression(1)),
             new VariableInitializer("b", new PrimitiveExpression(2)),
         }
     });
 }
Example #10
0
 public void GenericMethodDeclarationTest()
 {
     ParseUtilCSharp.AssertTypeMember(
         "T MyMethod<T>(T a) {} ",
         new MethodDeclaration {
         ReturnType     = new SimpleType("T"),
         Name           = "MyMethod",
         TypeParameters = { new TypeParameterDeclaration {
                                Name = "T"
                            } },
         Parameters = { new ParameterDeclaration(new SimpleType("T"), "a") },
         Body       = new BlockStatement()
     });
 }
Example #11
0
 public void MethodImplementingGenericInterfaceTest()
 {
     ParseUtilCSharp.AssertTypeMember(
         "int MyInterface<string>.MyMethod() {} ",
         new MethodDeclaration {
         ReturnType = new PrimitiveType("int"),
         PrivateImplementationType = new SimpleType("MyInterface")
         {
             TypeArguments = { new PrimitiveType("string") }
         },
         Name = "MyMethod",
         Body = new BlockStatement()
     });
 }
 public void SimpleEventDeclarationTest()
 {
     ParseUtilCSharp.AssertTypeMember(
         "event EventHandler MyEvent;",
         new EventDeclaration {
         ReturnType = new SimpleType("EventHandler"),
         Variables  =
         {
             new VariableInitializer {
                 Name = "MyEvent"
             }
         }
     });
 }
Example #13
0
 public void Arglist()
 {
     ParseUtilCSharp.AssertTypeMember(
         "void M(__arglist) {}",
         new MethodDeclaration {
         ReturnType = new PrimitiveType("void"),
         Name       = "M",
         Body       = new BlockStatement(),
         Parameters =
         {
             new ParameterDeclaration(new PrimitiveType("__arglist"), "")
         }
     });
 }
Example #14
0
 public void AsyncAsyncAsync()
 {
     ParseUtilCSharp.AssertTypeMember(
         "async async async(async async) {}",
         new MethodDeclaration {
         Modifiers  = Modifiers.Async,
         ReturnType = new SimpleType("async"),
         Name       = "async",
         Body       = new BlockStatement(),
         Parameters =
         {
             new ParameterDeclaration(new SimpleType("async"), "async")
         }
     });
 }
 public void FieldWithFixedSize()
 {
     ParseUtilCSharp.AssertTypeMember(
         "public unsafe fixed int Field[100];",
         new FixedFieldDeclaration()
     {
         Modifiers  = Modifiers.Public | Modifiers.Unsafe,
         ReturnType = new PrimitiveType("int"),
         Variables  =
         {
             new FixedVariableInitializer {
                 Name            = "Field",
                 CountExpression = new PrimitiveExpression(100)
             }
         }
     });
 }
Example #16
0
 public void AttributeOnMethodParameter()
 {
     ParseUtilCSharp.AssertTypeMember(
         "void M([In] int p);",
         new MethodDeclaration {
         ReturnType = new PrimitiveType("void"),
         Name       = "M",
         Parameters =
         {
             new ParameterDeclaration {
                 Attributes =         { new AttributeSection(new Attribute{
                         Type = new SimpleType("In")
                     }) },
                 Type = new PrimitiveType("int"),
                 Name = "p"
             }
         }
     });
 }
 public void AddRemoveEventDeclarationTest()
 {
     ParseUtilCSharp.AssertTypeMember(
         "public event System.EventHandler MyEvent { add { } remove { } }",
         new CustomEventDeclaration {
         Modifiers  = Modifiers.Public,
         ReturnType = new MemberType {
             Target     = new SimpleType("System"),
             MemberName = "EventHandler"
         },
         Name        = "MyEvent",
         AddAccessor = new Accessor {
             Body = new BlockStatement()
         },
         RemoveAccessor = new Accessor {
             Body = new BlockStatement()
         }
     });
 }
Example #18
0
 public void MultipleEventDeclarationTest()
 {
     ParseUtilCSharp.AssertTypeMember(
         "public event EventHandler A = null, B = delegate {};",
         new EventDeclaration {
         Modifiers  = Modifiers.Public,
         ReturnType = new SimpleType("EventHandler"),
         Variables  =
         {
             new VariableInitializer {
                 Name        = "A",
                 Initializer = new NullReferenceExpression()
             },
             new VariableInitializer {
                 Name        = "B",
                 Initializer = new AnonymousMethodExpression()
             }
         }
     });
 }
Example #19
0
 public void AttributeOnSetterValue()
 {
     ParseUtilCSharp.AssertTypeMember(
         "int P { get; [param: In] set; }",
         new PropertyDeclaration {
         ReturnType = new PrimitiveType("int"),
         Name       = "P",
         Getter     = new Accessor(),
         Setter     = new Accessor {
             Attributes =
             {
                 new AttributeSection {
                     AttributeTarget = "param",
                     Attributes      = { new Attribute {
                                             Type = new SimpleType("In")
                                         } },
                 }
             },
         }
     });
 }
Example #20
0
 public void GenericMethodDeclarationWithConstraintTest()
 {
     ParseUtilCSharp.AssertTypeMember(
         "T MyMethod<T>(T a) where T : ISomeInterface {} ",
         new MethodDeclaration {
         ReturnType     = new SimpleType("T"),
         Name           = "MyMethod",
         TypeParameters = { new TypeParameterDeclaration {
                                Name = "T"
                            } },
         Parameters  = { new ParameterDeclaration(new SimpleType("T"), "a") },
         Constraints =
         {
             new Constraint {
                 TypeParameter = new SimpleType("T"),
                 BaseTypes     = { new SimpleType("ISomeInterface") }
             }
         },
         Body = new BlockStatement()
     });
 }
 public void FieldWithArrayInitializer()
 {
     ParseUtilCSharp.AssertTypeMember(
         "public static readonly int[] arr = { 1, 2, 3 };",
         new FieldDeclaration {
         Modifiers  = Modifiers.Public | Modifiers.Static | Modifiers.Readonly,
         ReturnType = new PrimitiveType("int").MakeArrayType(),
         Variables  =
         {
             new VariableInitializer {
                 Name        = "arr",
                 Initializer = new ArrayInitializerExpression{
                     Elements =
                     {
                         new PrimitiveExpression(1),
                         new PrimitiveExpression(2),
                         new PrimitiveExpression(3)
                     }
                 }
             }
         }
     });
 }
Example #22
0
 public void GenericMethodDeclarationWithThreeConstraintsTest()
 {
     ParseUtilCSharp.AssertTypeMember(
         "A MyMethod<A, B, C>() where B : BB where A : BA, IA where C : class {} ",
         new MethodDeclaration {
         ReturnType     = new SimpleType("A"),
         Name           = "MyMethod",
         TypeParameters =
         {
             new TypeParameterDeclaration {
                 Name = "A"
             },
             new TypeParameterDeclaration {
                 Name = "B"
             },
             new TypeParameterDeclaration {
                 Name = "C"
             }
         },
         Constraints =
         {
             new Constraint {
                 TypeParameter = new SimpleType("B"),
                 BaseTypes     = { new SimpleType("BB")  }
             },
             new Constraint {
                 TypeParameter = new SimpleType("A"),
                 BaseTypes     = { new SimpleType("BA"), new SimpleType("IA") }
             },
             new Constraint {
                 TypeParameter = new SimpleType("C"),
                 BaseTypes     = { new PrimitiveType("class") }
             }
         },
         Body = new BlockStatement()
     });
 }
Example #23
0
 public void OptionalParameterTest()
 {
     ParseUtilCSharp.AssertTypeMember(
         "public void Foo(string bar = null, int baz = 0) { }",
         new MethodDeclaration {
         Modifiers  = Modifiers.Public,
         ReturnType = new PrimitiveType("void"),
         Name       = "Foo",
         Body       = new BlockStatement(),
         Parameters =
         {
             new ParameterDeclaration {
                 Type = new PrimitiveType("string"),
                 Name = "bar",
                 DefaultExpression = new NullReferenceExpression()
             },
             new ParameterDeclaration {
                 Type = new PrimitiveType("int"),
                 Name = "baz",
                 DefaultExpression = new PrimitiveExpression(0)
             }
         }
     });
 }
Example #24
0
 public void FieldWithFixedSize()
 {
     ParseUtilCSharp.AssertTypeMember(
         "public unsafe fixed int Field[100];",
         new FieldDeclaration());
 }