public void GenericVoidMethodInInterface() { ParseUtilCSharp.AssertGlobal( @"interface MyInterface { void MyMethod<T>(T a) where T : ISomeInterface; } ", new TypeDeclaration { ClassType = ClassType.Interface, Name = "MyInterface", Members = { new MethodDeclaration { ReturnType = new PrimitiveType("void"), 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") } } } } } }); }
public void AttributesOnTypeParameter() { ParseUtilCSharp.AssertGlobal( "class Test<[A,B]C> {}", new TypeDeclaration { ClassType = ClassType.Class, Name = "Test", TypeParameters = { new TypeParameterDeclaration { Attributes = { new AttributeSection { Attributes = { new Attribute { Type = new SimpleType("A") }, new Attribute { Type = new SimpleType("B") } } } }, Name = "C" } } }); }
public void VoidMethodImplementingGenericInterfaceTest() { ParseUtilCSharp.AssertGlobal( "void MyInterface<string>.MyMethod() {} ", new MethodDeclaration { ReturnType = new PrimitiveType("void"), PrivateImplementationType = new SimpleType("MyInterface"), Name = "MyMethod", Body = new BlockStatement() }); }
public void GenericClassTypeDeclarationTest() { ParseUtilCSharp.AssertGlobal( "public class G<T> {}", new TypeDeclaration { ClassType = ClassType.Class, Modifiers = Modifiers.Public, Name = "G", TypeParameters = { new TypeParameterDeclaration { Name = "T" } } }); }
public void ComplexGenericInterfaceTypeDeclarationTest() { ParseUtilCSharp.AssertGlobal( "public interface Generic<in T, out S> : System.IComparable where S : G<T[]>, new() where T : MyNamespace.IMyInterface {}", new TypeDeclaration { ClassType = ClassType.Interface, Modifiers = Modifiers.Public, Name = "Generic", TypeParameters = { new TypeParameterDeclaration { Variance = VarianceModifier.Contravariant, Name = "T" }, new TypeParameterDeclaration { Variance = VarianceModifier.Covariant, Name = "S" } }, BaseTypes = { new MemberType { Target = new SimpleType("System"), MemberName = "IComparable" } }, Constraints = { new Constraint { TypeParameter = new SimpleType("S"), BaseTypes = { new SimpleType { Identifier = "G", TypeArguments ={ new SimpleType("T").MakeArrayType() } }, new PrimitiveType("new") } }, new Constraint { TypeParameter = new SimpleType("T"), BaseTypes = { new MemberType { Target = new SimpleType("MyNamespace"), MemberName = "IMyInterface" } } } } }); }
public void EnumWithIncorrectNewlineAfterIntegerLiteral() { ParseUtilCSharp.AssertGlobal( "enum DisplayFlags { D = 4\r\r\n}", new TypeDeclaration { ClassType = ClassType.Enum, Name = "DisplayFlags", Members = { new EnumMemberDeclaration { Name = "D", Initializer = new PrimitiveExpression(4) } } }); }
public void SimpleCSharpDelegateDeclarationTest() { ParseUtilCSharp.AssertGlobal( "public delegate void MyDelegate(int a, int secondParam, MyObj lastParam);", new DelegateDeclaration { Modifiers = Modifiers.Public, ReturnType = new PrimitiveType("void"), Name = "MyDelegate", Parameters = { new ParameterDeclaration(new PrimitiveType("int"), "a"), new ParameterDeclaration(new PrimitiveType("int"), "secondParam"), new ParameterDeclaration(new SimpleType("MyObj"), "lastParam") } }); }
public void GenericClassWithWhere() { ParseUtilCSharp.AssertGlobal( @"public class Test<T> where T : IMyInterface { }", new TypeDeclaration { ClassType = ClassType.Class, Modifiers = Modifiers.Public, Name = "Test", TypeParameters = { new TypeParameterDeclaration { Name = "T" } }, Constraints = { new Constraint { TypeParameter = new SimpleType("T"), BaseTypes = { new SimpleType("IMyInterface") } } } }); }
public void GenericDelegateDeclarationTest() { ParseUtilCSharp.AssertGlobal( "public delegate T CreateObject<T>() where T : ICloneable;", new DelegateDeclaration { Modifiers = Modifiers.Public, ReturnType = new SimpleType("T"), Name = "CreateObject", TypeParameters = { new TypeParameterDeclaration { Name = "T" } }, Constraints = { new Constraint { TypeParameter = "T", BaseTypes = { new SimpleType("ICloneable") } } } }); }
public void ShadowingMethodInInterface() { ParseUtilCSharp.AssertGlobal( @"interface MyInterface : IDisposable { new void Dispose(); } ", new TypeDeclaration { ClassType = ClassType.Interface, BaseTypes = { new SimpleType("IDisposable") }, Members = { new MethodDeclaration { Modifiers = Modifiers.New, ReturnType = new PrimitiveType("void"), Name = "Dispose" } } }); }
public void ContextSensitiveKeywordTest() { ParseUtilCSharp.AssertGlobal( "partial class partial<[partial: where] where> where where : partial<where> { }", new TypeDeclaration { ClassType = ClassType.Class, Modifiers = Modifiers.Partial, Name = "partial", TypeParameters = { new TypeParameterDeclaration { Attributes = { new AttributeSection { AttributeTarget = "partial", Attributes = { new Attribute { Type = new SimpleType("where") } } } }, Name = "where" } }, Constraints = { new Constraint { TypeParameter = new SimpleType("where"), BaseTypes = { new SimpleType { Identifier = "partial", TypeArguments ={ new SimpleType("where") } } } } } }); }
public void TwoAttributesInSameSection() { ParseUtilCSharp.AssertGlobal( @"[A, B] class Test {}", new TypeDeclaration { Name = "Test", Attributes = { new AttributeSection { Attributes = { new Attribute { Type = new SimpleType("A") }, new Attribute { Type = new SimpleType("B") } } } } }); }
public void ComplexClassTypeDeclarationTest() { ParseUtilCSharp.AssertGlobal( @" [MyAttr()] public abstract class MyClass : MyBase, Interface1, My.Test.Interface2 { }", new TypeDeclaration { ClassType = ClassType.Class, Attributes = { new AttributeSection { Attributes = { new Attribute { Type = new SimpleType("MyAttr") } } } }, Modifiers = Modifiers.Public | Modifiers.Abstract, Name = "MyClass", BaseTypes = { new SimpleType("MyBase"), new SimpleType("Interface1"), new MemberType { Target = new MemberType { Target = new SimpleType("My"), MemberName = "Test" }, MemberName = "Interface2" } } }); }