当前位置: 首页>>代码示例>>C#>>正文


C# VBParser.Parse方法代码示例

本文整理汇总了C#中NArrange.VisualBasic.VBParser.Parse方法的典型用法代码示例。如果您正苦于以下问题:C# VBParser.Parse方法的具体用法?C# VBParser.Parse怎么用?C# VBParser.Parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NArrange.VisualBasic.VBParser的用法示例。


在下文中一共展示了VBParser.Parse方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ExpectedBlockCloseTest

        public void ExpectedBlockCloseTest()
        {
            StringReader reader = new StringReader(
                "namespace SampleNamespace");

            VBParser parser = new VBParser();
            parser.Parse(reader);
        }
开发者ID:MarcStan,项目名称:NArrange,代码行数:8,代码来源:VBParserTests.cs

示例2: ParseSingleNamespaceTest

        public void ParseSingleNamespaceTest()
        {
            VBParser parser = new VBParser();

            VBTestFile testFile = VBTestUtilities.GetSingleNamespaceFile();
            using (TextReader reader = testFile.GetReader())
            {
                ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

                Assert.IsNotNull(elements, "Code element collection should not be null.");
                Assert.AreEqual(1, elements.Count, "An unexpected number of elements were parsed.");

                NamespaceElement namespaceElement = elements[0] as NamespaceElement;
                Assert.IsNotNull(namespaceElement, "Expected a NamespaceElement.");
                Assert.AreEqual("SampleNamespace", namespaceElement.Name, "Unexpected namespace name.");
                Assert.IsNotNull(namespaceElement.Children, "Children collection should not be null.");
                Assert.AreEqual(0, namespaceElement.Children.Count, "Children collection should not be null.");
            }
        }
开发者ID:MarcStan,项目名称:NArrange,代码行数:19,代码来源:VBParserTests.cs

示例3: ParseAssemblyAttributesTest

        public void ParseAssemblyAttributesTest()
        {
            VBParser parser = new VBParser();

            VBTestFile testFile = VBTestUtilities.GetAssemblyAttributesFile();
            using (TextReader reader = testFile.GetReader())
            {
                ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

                Assert.IsNotNull(elements, "Code element collection should not be null.");
                Assert.AreEqual(15, elements.Count, "An unexpected number of elements were parsed.");

                //
                // Using statements
                //
                UsingElement usingElement;

                usingElement = elements[0] as UsingElement;
                Assert.IsNotNull(usingElement, "Element is not a UsingElement.");
                Assert.AreEqual("System.Reflection", usingElement.Name, "Unexpected name.");

                usingElement = elements[1] as UsingElement;
                Assert.IsNotNull(usingElement, "Element is not a UsingElement.");
                Assert.AreEqual("System.Runtime.CompilerServices", usingElement.Name, "Unexpected name.");

                usingElement = elements[2] as UsingElement;
                Assert.IsNotNull(usingElement, "Element is not a UsingElement.");
                Assert.AreEqual("System.Runtime.InteropServices", usingElement.Name, "Unexpected name.");

                //
                // Attributes
                //
                AttributeElement attributeElement;

                attributeElement = elements[3] as AttributeElement;
                Assert.IsNotNull(attributeElement, "Element is not an AttributeElement.");
                Assert.AreEqual("assembly", attributeElement.Target, "Unexpected attribute target.");
                Assert.AreEqual("AssemblyTitle", attributeElement.Name, "Unexpected attribute name.");
                Assert.AreEqual("\"NArrange.Core.Tests\"", attributeElement.BodyText, "Unexpected attribute text.");
                Assert.AreEqual(3, attributeElement.HeaderComments.Count,
                    "An unexpected number of header comment lines were parsed.");

                attributeElement = elements[4] as AttributeElement;
                Assert.IsNotNull(attributeElement, "Element is not an AttributeElement.");
                Assert.AreEqual("assembly", attributeElement.Target, "Unexpected attribute target.");
                Assert.AreEqual("AssemblyDescription", attributeElement.Name, "Unexpected attribute name.");
                Assert.AreEqual("\"\"", attributeElement.BodyText, "Unexpected attribute text.");
                Assert.AreEqual(0, attributeElement.HeaderComments.Count,
                    "An unexpected number of header comment lines were parsed.");

                attributeElement = elements[5] as AttributeElement;
                Assert.IsNotNull(attributeElement, "Element is not an AttributeElement.");
                Assert.AreEqual("assembly", attributeElement.Target, "Unexpected attribute target.");
                Assert.AreEqual("AssemblyConfiguration", attributeElement.Name, "Unexpected attribute name.");
                Assert.AreEqual("\"\"", attributeElement.BodyText, "Unexpected attribute text.");
                Assert.AreEqual(0, attributeElement.HeaderComments.Count,
                    "An unexpected number of header comment lines were parsed.");

                attributeElement = elements[6] as AttributeElement;
                Assert.IsNotNull(attributeElement, "Element is not an AttributeElement.");
                Assert.AreEqual("assembly", attributeElement.Target, "Unexpected attribute target.");
                Assert.AreEqual("AssemblyCompany", attributeElement.Name, "Unexpected attribute name.");
                Assert.AreEqual("\"\"", attributeElement.BodyText, "Unexpected attribute text.");
                Assert.AreEqual(0, attributeElement.HeaderComments.Count,
                    "An unexpected number of header comment lines were parsed.");

                attributeElement = elements[7] as AttributeElement;
                Assert.IsNotNull(attributeElement, "Element is not an AttributeElement.");
                Assert.AreEqual("assembly", attributeElement.Target, "Unexpected attribute target.");
                Assert.AreEqual("AssemblyProduct", attributeElement.Name, "Unexpected attribute name.");
                Assert.AreEqual("\"NArrange.Core.Tests\"", attributeElement.BodyText, "Unexpected attribute text.");
                Assert.AreEqual(0, attributeElement.HeaderComments.Count,
                    "An unexpected number of header comment lines were parsed.");

                attributeElement = elements[8] as AttributeElement;
                Assert.IsNotNull(attributeElement, "Element is not an AttributeElement.");
                Assert.AreEqual("assembly", attributeElement.Target, "Unexpected attribute target.");
                Assert.AreEqual("AssemblyCopyright", attributeElement.Name, "Unexpected attribute name.");
                Assert.AreEqual("\"Copyright ©  2007\"", attributeElement.BodyText, "Unexpected attribute text.");
                Assert.AreEqual(0, attributeElement.HeaderComments.Count,
                    "An unexpected number of header comment lines were parsed.");

                attributeElement = elements[9] as AttributeElement;
                Assert.IsNotNull(attributeElement, "Element is not an AttributeElement.");
                Assert.AreEqual("assembly", attributeElement.Target, "Unexpected attribute target.");
                Assert.AreEqual("AssemblyTrademark", attributeElement.Name, "Unexpected attribute name.");
                Assert.AreEqual("\"\"", attributeElement.BodyText, "Unexpected attribute text.");
                Assert.AreEqual(0, attributeElement.HeaderComments.Count,
                    "An unexpected number of header comment lines were parsed.");

                attributeElement = elements[10] as AttributeElement;
                Assert.IsNotNull(attributeElement, "Element is not an AttributeElement.");
                Assert.AreEqual("assembly", attributeElement.Target, "Unexpected attribute target.");
                Assert.AreEqual("AssemblyCulture", attributeElement.Name, "Unexpected attribute name.");
                Assert.AreEqual("\"\"", attributeElement.BodyText, "Unexpected attribute text.");
                Assert.AreEqual(0, attributeElement.HeaderComments.Count,
                    "An unexpected number of header comment lines were parsed.");

                attributeElement = elements[11] as AttributeElement;
                Assert.IsNotNull(attributeElement, "Element is not an AttributeElement.");
//.........这里部分代码省略.........
开发者ID:MarcStan,项目名称:NArrange,代码行数:101,代码来源:VBParserTests.cs

示例4: ParseClassUnspecifiedAccessTest

        public void ParseClassUnspecifiedAccessTest()
        {
            StringReader reader = new StringReader(
                "class Test\r\n" +
                "class Nested\r\n" +
                "end class\r\n" +
                "end class");

            VBParser parser = new VBParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

            Assert.AreEqual(1, elements.Count, "An unexpected number of elements were parsed.");
            TypeElement typeElement = elements[0] as TypeElement;
            Assert.IsNotNull(typeElement, "Element is not a TypeElement.");
            Assert.AreEqual("Test", typeElement.Name, "Unexpected name.");
            Assert.AreEqual(CodeAccess.None, typeElement.Access, "Unexpected code access.");
            Assert.AreEqual(TypeElementType.Class, typeElement.Type, "Unexpected type element type.");

            Assert.AreEqual(1, typeElement.Children.Count, "An unexpected number of child elements were parsed.");
            TypeElement nestedtypeElement = typeElement.Children[0] as TypeElement;
            Assert.IsNotNull(nestedtypeElement, "Element is not a TypeElement.");
            Assert.AreEqual("Nested", nestedtypeElement.Name, "Unexpected name.");
            Assert.AreEqual(CodeAccess.None, nestedtypeElement.Access, "Unexpected code access.");
            Assert.AreEqual(TypeElementType.Class, nestedtypeElement.Type, "Unexpected type element type.");
        }
开发者ID:MarcStan,项目名称:NArrange,代码行数:25,代码来源:VBParserTests.cs

示例5: ParseClassUnclosedTypeParameterTest

        public void ParseClassUnclosedTypeParameterTest()
        {
            StringReader reader = new StringReader(
                "Public Class Test(Of T\r\nEnd Class");

            VBParser parser = new VBParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);
        }
开发者ID:MarcStan,项目名称:NArrange,代码行数:8,代码来源:VBParserTests.cs

示例6: ParseClassSimpleTest

        public void ParseClassSimpleTest()
        {
            StringReader reader = new StringReader(
                "public class Test\r\n" +
                "end class");

            VBParser parser = new VBParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

            Assert.AreEqual(1, elements.Count, "An unexpected number of elements were parsed.");
            TypeElement typeElement = elements[0] as TypeElement;
            Assert.IsNotNull(typeElement, "Element is not a TypeElement.");
            Assert.AreEqual("Test", typeElement.Name, "Unexpected name.");
            Assert.AreEqual(CodeAccess.Public, typeElement.Access, "Unexpected code access.");
            Assert.AreEqual(TypeElementType.Class, typeElement.Type, "Unexpected type element type.");
        }
开发者ID:MarcStan,项目名称:NArrange,代码行数:16,代码来源:VBParserTests.cs

示例7: ParseClassMultipleTypeParameterTest3

        public void ParseClassMultipleTypeParameterTest3()
        {
            StringReader reader = new StringReader(
                "Partial Public Class NewClass(Of T as {new, IDisposable}, S as new, R)\r\n" +
                "End Class");

            VBParser parser = new VBParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

            TypeElement classElement = elements[0] as TypeElement;
            Assert.IsNotNull(classElement, "Expected a class element");
            Assert.AreEqual(TypeElementType.Class, classElement.Type, "Expected a class.");
            Assert.AreEqual("NewClass", classElement.Name, "Unexpected class name.");
            Assert.AreEqual(CodeAccess.Public, classElement.Access, "Unexpected access.");
            Assert.IsTrue(classElement.IsPartial, "Expected a partial class.");
            Assert.AreEqual(3, classElement.TypeParameters.Count, "Unexpected number of type parameters.");
            Assert.AreEqual("T", classElement.TypeParameters[0].Name);
            Assert.AreEqual(2, classElement.TypeParameters[0].Constraints.Count);
            Assert.AreEqual("new", classElement.TypeParameters[0].Constraints[0]);
            Assert.AreEqual("IDisposable", classElement.TypeParameters[0].Constraints[1]);
            Assert.AreEqual("S", classElement.TypeParameters[1].Name);
            Assert.AreEqual(1, classElement.TypeParameters[1].Constraints.Count);
            Assert.AreEqual("new", classElement.TypeParameters[1].Constraints[0]);
            Assert.AreEqual("R", classElement.TypeParameters[2].Name);
            Assert.AreEqual(0, classElement.TypeParameters[2].Constraints.Count);
        }
开发者ID:MarcStan,项目名称:NArrange,代码行数:26,代码来源:VBParserTests.cs

示例8: ParseClassMultipleTypeParameterInvalidTest3

        public void ParseClassMultipleTypeParameterInvalidTest3()
        {
            StringReader reader = new StringReader(
                "Partial Public Class NewClass(Of T as new, IDisposable, S as new, IComparable})\r\n" +
                "End Class");

            VBParser parser = new VBParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

            Assert.Fail();
        }
开发者ID:MarcStan,项目名称:NArrange,代码行数:11,代码来源:VBParserTests.cs

示例9: ParseUsingEmptyTypeOrNamespaceTest

        public void ParseUsingEmptyTypeOrNamespaceTest()
        {
            StringReader reader = new StringReader(
                "Imports Test = \r\n");

            VBParser parser = new VBParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);
        }
开发者ID:MarcStan,项目名称:NArrange,代码行数:8,代码来源:VBParserTests.cs

示例10: ParseUnkownKeywordTest

        public void ParseUnkownKeywordTest()
        {
            StringReader reader = new StringReader("Blah");

            VBParser parser = new VBParser();
            parser.Parse(reader);
        }
开发者ID:MarcStan,项目名称:NArrange,代码行数:7,代码来源:VBParserTests.cs

示例11: ParseUnhandledPreprocessorTest

        public void ParseUnhandledPreprocessorTest()
        {
            StringReader reader = new StringReader(
                "Public Class Test\r\n" +
                "#Const TEST = 1\r\n" +
                "End Class");

            VBParser parser = new VBParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);
        }
开发者ID:MarcStan,项目名称:NArrange,代码行数:10,代码来源:VBParserTests.cs

示例12: ParseTypeImplementsTest

        public void ParseTypeImplementsTest()
        {
            StringReader reader = new StringReader(
                "Public Class TestClass : Implements IList\r\n" +
                "\tImplements IDisposable, IBindingList\r\n" +
                "End Class");

            VBParser parser = new VBParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

            Assert.AreEqual(1, elements.Count, "An unexpected number of elements were parsed.");
            TypeElement typeElement = elements[0] as TypeElement;
            Assert.IsNotNull(typeElement, "Expected a type element.");
            Assert.AreEqual(TypeElementType.Class, typeElement.Type, "Unexpected type element type.");
            Assert.AreEqual(3, typeElement.Interfaces.Count);
            Assert.AreEqual("IList", typeElement.Interfaces[0].Name);
            Assert.AreEqual("IDisposable", typeElement.Interfaces[1].Name);
            Assert.AreEqual("IBindingList", typeElement.Interfaces[2].Name);
            foreach (InterfaceReference interfaceReference in typeElement.Interfaces)
            {
                Assert.AreEqual(InterfaceReferenceType.Interface, interfaceReference.ReferenceType);
            }
        }
开发者ID:MarcStan,项目名称:NArrange,代码行数:23,代码来源:VBParserTests.cs

示例13: ParseSubTest

        public void ParseSubTest()
        {
            StringReader reader = new StringReader(
                "Private Sub DoSomething()\r\n" +
                "End Sub");

            VBParser parser = new VBParser();
            ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

            Assert.AreEqual(1, elements.Count, "An unexpected number of elements were parsed.");
            MethodElement methodElement = elements[0] as MethodElement;
            Assert.IsNotNull(methodElement, "Element is not a MethodElement.");
            Assert.AreEqual("DoSomething", methodElement.Name, "Unexpected name.");
            Assert.AreEqual(CodeAccess.Private, methodElement.Access, "Unexpected code access.");
            Assert.IsNull(methodElement.Type, "Unexpected member type.");

            reader = new StringReader(
                "Sub DoSomething()\r\n" +
                "End Sub");

            elements = parser.Parse(reader);

            Assert.AreEqual(1, elements.Count, "An unexpected number of elements were parsed.");
            methodElement = elements[0] as MethodElement;
            Assert.IsNotNull(methodElement, "Element is not a MethodElement.");
            Assert.AreEqual("DoSomething", methodElement.Name, "Unexpected name.");
            Assert.AreEqual(CodeAccess.None, methodElement.Access, "Unexpected code access.");
            Assert.IsNull(methodElement.Type, "Unexpected member type.");
        }
开发者ID:MarcStan,项目名称:NArrange,代码行数:29,代码来源:VBParserTests.cs

示例14: ParseSubExternalTest

        public void ParseSubExternalTest()
        {
            string[] variations =
            {
                "Public Declare Ansi Sub ExternalSub Lib \"Some.dll\" Alias \"doit\" (ByVal filename As String)",
                "Public Declare Ansi Sub _\r\nExternalSub Lib _\r\n\"Some.dll\" Alias _\r\n \"doit\" (ByVal filename As String)"
            };

            foreach (string variation in variations)
            {
                StringReader reader = new StringReader(variation);

                VBParser parser = new VBParser();
                ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

                Assert.AreEqual(1, elements.Count, "An unexpected number of elements were parsed.");
                MethodElement methodElement = elements[0] as MethodElement;
                Assert.IsNotNull(methodElement, "Element is not a MethodElement.");
                Assert.AreEqual("ExternalSub", methodElement.Name, "Unexpected name.");
                Assert.AreEqual(CodeAccess.Public, methodElement.Access, "Unexpected code access.");
                Assert.AreEqual("ByVal filename As String", methodElement.Parameters, "Unexpected parameters.");
                Assert.IsNull(methodElement.Type, "Unexpected return type.");
                Assert.AreEqual("Ansi", methodElement[VBExtendedProperties.ExternalModifier], "Unexpected external modifier.");
                Assert.AreEqual("Some.dll", methodElement[VBExtendedProperties.ExternalLibrary], "Unexpected external library.");
                Assert.AreEqual("doit", methodElement[VBExtendedProperties.ExternalAlias], "Unexpected external alias.");
            }
        }
开发者ID:MarcStan,项目名称:NArrange,代码行数:27,代码来源:VBParserTests.cs

示例15: ParseStructDefinitionTest

        public void ParseStructDefinitionTest()
        {
            VBParser parser = new VBParser();

            VBTestFile testFile = VBTestUtilities.GetStructDefinitionFile();
            using (TextReader reader = testFile.GetReader())
            {
                ReadOnlyCollection<ICodeElement> elements = parser.Parse(reader);

                Assert.IsNotNull(elements, "Code element collection should not be null.");
                Assert.AreEqual(2, elements.Count, "An unexpected number of elements were parsed.");

                UsingElement using1 = elements[0] as UsingElement;
                Assert.IsNotNull(using1, "Expected a UsingElement.");
                Assert.AreEqual("System", using1.Name, "Unexpected using name.");

                NamespaceElement namespaceElement = elements[1] as NamespaceElement;
                Assert.IsNotNull(namespaceElement, "Expected a NamespaceElement.");
                Assert.AreEqual("SampleNamespace", namespaceElement.Name, "Unexpected namespace name.");

                Assert.IsNotNull(namespaceElement.Children, "Namespace Children collection should not be null.");
                Assert.AreEqual(1, namespaceElement.Children.Count, "An unexpected number of namespace child elements were parsed.");

                TypeElement structElement = namespaceElement.Children[0] as TypeElement;
                Assert.IsNotNull(structElement, "Expected a TypeElement.");
                Assert.AreEqual(TypeElementType.Structure, structElement.Type, "Expected type to be a structure.");
                Assert.IsFalse(structElement.IsStatic, "Structure should not be static.");
                Assert.IsFalse(structElement.IsSealed, "Structures should not be sealed.");
                Assert.AreEqual("SampleStruct", structElement.Name, "Unexpected structure name.");
                Assert.AreEqual(3, structElement.HeaderComments.Count,
                    "An unexpected number of class header comment lines were parsed.");
                foreach (ICommentElement comment in structElement.HeaderComments)
                {
                    Assert.AreEqual(CommentType.XmlLine, comment.Type, "Structure header comment should be an XML comment.");
                }
                Assert.AreEqual(CodeAccess.Public, structElement.Access, "Unexpected code access level.");
            }
        }
开发者ID:MarcStan,项目名称:NArrange,代码行数:38,代码来源:VBParserTests.cs


注:本文中的NArrange.VisualBasic.VBParser.Parse方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。