예제 #1
0
        public void VBNetCustomEventsStatementTest()
        {
            string           code            = @" Public Custom Event TestEvent As EventHandler
        AddHandler(ByVal value As EventHandler)
            Handlers = CType([Delegate].Combine(Handlers, value), _
                EventHandler)
        End AddHandler

        RemoveHandler(ByVal value as EventHandler)
            Handlers = CType([Delegate].Remove(Handlers, value), _
                EventHandler)
        End RemoveHandler

        RaiseEvent(ByVal sender As Object, ByVal e As EventArgs)
            Dim TempHandlers As EventHandler = Handlers

            If TempHandlers IsNot Nothing Then
                TempHandlers(sender, e)
            End If
        End RaiseEvent
    End Event";
            EventDeclaration customEventDecl = ParseUtilVBNet.ParseTypeMember <EventDeclaration>(code);

            Assert.IsNotNull(customEventDecl);
            Assert.AreEqual("TestEvent", customEventDecl.Name);
        }
예제 #2
0
        public void VBNetSimpleGetSetPropertyDeclarationTest()
        {
            PropertyDeclaration pd = ParseUtilVBNet.ParseTypeMember <PropertyDeclaration>("Property MyProperty As Integer \n Get \n End Get \n Set \n End Set\nEnd Property");

            Assert.AreEqual("MyProperty", pd.Name);
            Assert.IsTrue(pd.HasGetRegion);
            Assert.IsTrue(pd.HasSetRegion);
        }
예제 #3
0
        public void VBNetConstructorDeclarationTest1()
        {
            string program            = @"Sub New()
								End Sub"                                ;
            ConstructorDeclaration cd = ParseUtilVBNet.ParseTypeMember <ConstructorDeclaration>(program);

            Assert.IsTrue(cd.ConstructorInitializer.IsNull);
        }
예제 #4
0
        public void VBNetConstructorDeclarationTest2()
        {
            ConstructorDeclaration cd = ParseUtilVBNet.ParseTypeMember <ConstructorDeclaration>("Sub New(x As Integer, Optional y As String) \nEnd Sub");

            Assert.AreEqual(2, cd.Parameters.Count);
            Assert.AreEqual("Integer", cd.Parameters[0].TypeReference.Type);
            Assert.AreEqual("String", cd.Parameters[1].TypeReference.Type);
            Assert.AreEqual(ParamModifier.Optional, cd.Parameters[1].ParamModifier & ParamModifier.Optional);
        }
예제 #5
0
        public void VBNetSimpleEventDeclarationTest()
        {
            EventDeclaration ed = ParseUtilVBNet.ParseTypeMember <EventDeclaration>("event MyEvent(x as Integer)");

            Assert.AreEqual(1, ed.Parameters.Count);
            Assert.AreEqual("MyEvent", ed.Name);
            Assert.IsFalse(ed.HasAddRegion);
            Assert.IsFalse(ed.HasRemoveRegion);
        }
예제 #6
0
        public void VBNetDeclareDeclarationTest()
        {
            string             program = "Declare Ansi Function GetUserName Lib \"advapi32.dll\" Alias \"GetUserNameA\" (ByVal lpBuffer As String, ByRef nSize As Integer) As Integer\n";
            DeclareDeclaration dd      = ParseUtilVBNet.ParseTypeMember <DeclareDeclaration>(program);

            Assert.AreEqual("System.Int32", dd.TypeReference.SystemType);
            Assert.AreEqual("GetUserName", dd.Name);
            Assert.AreEqual("\"advapi32.dll\"", dd.Library);
            Assert.AreEqual("\"GetUserNameA\"", dd.Alias);
            Assert.AreEqual(CharsetModifier.ANSI, dd.Charset);
        }
        public void VBNetSimpleFieldDeclarationTest()
        {
            FieldDeclaration fd = ParseUtilVBNet.ParseTypeMember <FieldDeclaration>("myField As Integer(,,,)");

            Assert.AreEqual(1, fd.Fields.Count);

            Assert.AreEqual("Integer", ((VariableDeclaration)fd.Fields[0]).TypeReference.Type);
            Assert.AreEqual("System.Int32", ((VariableDeclaration)fd.Fields[0]).TypeReference.SystemType);
            Assert.AreEqual("myField", ((VariableDeclaration)fd.Fields[0]).Name);
            Assert.AreEqual(new int[] { 3 }, ((VariableDeclaration)fd.Fields[0]).TypeReference.RankSpecifier);
        }
예제 #8
0
        public void VBNetGenericMethodDeclarationTest()
        {
            MethodDeclaration md = ParseUtilVBNet.ParseTypeMember <MethodDeclaration>("Function MyMethod(Of T)(a As T) As T\nEnd Function ");

            Assert.AreEqual("T", md.TypeReference.Type);
            Assert.AreEqual(1, md.Parameters.Count);
            Assert.AreEqual("T", ((ParameterDeclarationExpression)md.Parameters[0]).TypeReference.Type);
            Assert.AreEqual("a", ((ParameterDeclarationExpression)md.Parameters[0]).ParameterName);

            Assert.AreEqual(1, md.Templates.Count);
            Assert.AreEqual("T", md.Templates[0].Name);
        }
예제 #9
0
        public void VBNetMethodWithModifiersRegionTest()
        {
            const string program = @"public shared sub MyMethod()
				OtherMethod()
			end sub"            ;

            MethodDeclaration md = ParseUtilVBNet.ParseTypeMember <MethodDeclaration>(program);

            Assert.AreEqual(2, md.StartLocation.Y, "StartLocation.Y");
            Assert.AreEqual(2, md.EndLocation.Y, "EndLocation.Y");
            Assert.AreEqual(2, md.StartLocation.X, "StartLocation.X");
        }
        public void VBNetImplictOperatorDeclarationTest()
        {
            string programm = @"Public Shared Operator + (ByVal v As Complex) As Complex
					Return v
				End Operator"                ;

            OperatorDeclaration od = ParseUtilVBNet.ParseTypeMember <OperatorDeclaration>(programm);

            Assert.IsFalse(od.IsConversionOperator);
            Assert.AreEqual(1, od.Parameters.Count);
            Assert.AreEqual(ConversionType.None, od.ConversionType);
            Assert.AreEqual("Complex", od.ConvertToType.Type);
        }
예제 #11
0
        public void VBNetGenericMethodDeclarationWithConstraintTest()
        {
            string            program = "Function MyMethod(Of T As { ISomeInterface })(a As T) As T\n End Function";
            MethodDeclaration md      = ParseUtilVBNet.ParseTypeMember <MethodDeclaration>(program);

            Assert.AreEqual("T", md.TypeReference.Type);
            Assert.AreEqual(1, md.Parameters.Count);
            Assert.AreEqual("T", ((ParameterDeclarationExpression)md.Parameters[0]).TypeReference.Type);
            Assert.AreEqual("a", ((ParameterDeclarationExpression)md.Parameters[0]).ParameterName);

            Assert.AreEqual(1, md.Templates.Count);
            Assert.AreEqual("T", md.Templates[0].Name);
            Assert.AreEqual(1, md.Templates[0].Bases.Count);
            Assert.AreEqual("ISomeInterface", md.Templates[0].Bases[0].Type);
        }