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


C# CSharpParser.Parse方法代码示例

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


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

示例1: UsingAliasDeclarationTest

		public void UsingAliasDeclarationTest()
		{
			string program = "using TESTME=System;\n" +
				"using myAlias=My.Name.Space;\n" +
				"using StringCollection = System.Collections.Generic.List<string>;\n";
			CSharpParser parser = new CSharpParser();
			SyntaxTree syntaxTree = parser.Parse(program);
			Assert.IsFalse(parser.HasErrors);
			
			Assert.IsTrue(3 <= syntaxTree.Children.Count());
			
			Assert.IsTrue(syntaxTree.Children.ElementAt(0) is UsingAliasDeclaration);
			UsingAliasDeclaration ud = (UsingAliasDeclaration)syntaxTree.Children.ElementAt(0);
			Assert.AreEqual("TESTME", ud.Alias);
			Assert.AreEqual("System", ud.Import.ToString());
			
			Assert.IsTrue(syntaxTree.Children.Where (c => c.Role != Roles.NewLine).ElementAt(1) is UsingAliasDeclaration);
			ud = (UsingAliasDeclaration)syntaxTree.Children.Where (c => c.Role != Roles.NewLine).ElementAt(1);
			Assert.AreEqual("myAlias", ud.Alias);
			Assert.AreEqual("My.Name.Space", ud.Import.ToString());
			
			Assert.IsTrue(syntaxTree.Children.Where (c => c.Role != Roles.NewLine).ElementAt(2) is UsingAliasDeclaration);
			ud = (UsingAliasDeclaration)syntaxTree.Children.Where (c => c.Role != Roles.NewLine).ElementAt(2);
			Assert.AreEqual("StringCollection", ud.Alias);
			Assert.AreEqual("System.Collections.Generic.List<string>", ud.Import.ToString());
		}
开发者ID:sphynx79,项目名称:dotfiles,代码行数:26,代码来源:UsingDeclarationTests.cs

示例2: UsingWithAliasing

		public void UsingWithAliasing()
		{
			string program = "using global::System;\n" +
				"using myAlias=global::My.Name.Space;\n" +
				"using a::b.c;\n";
			CSharpParser parser = new CSharpParser();
			CompilationUnit cu = parser.Parse(new StringReader(program));
			Assert.IsFalse(parser.HasErrors);
			
			Assert.AreEqual(3, cu.Children.Count());
			
			Assert.IsTrue(cu.Children.ElementAt(0) is UsingDeclaration);
			Assert.IsFalse(cu.Children.ElementAt(0) is UsingAliasDeclaration);
			UsingDeclaration ud = (UsingDeclaration)cu.Children.ElementAt(0);
			Assert.AreEqual("global::System", ud.Namespace);
			
			Assert.IsTrue(cu.Children.ElementAt(1) is UsingAliasDeclaration);
			UsingAliasDeclaration uad = (UsingAliasDeclaration)cu.Children.ElementAt(1);
			Assert.AreEqual("myAlias", uad.Alias);
			Assert.AreEqual("global::My.Name.Space", uad.Import.ToString());
			
			Assert.IsTrue(cu.Children.ElementAt(2) is UsingDeclaration);
			Assert.IsFalse(cu.Children.ElementAt(2) is UsingAliasDeclaration);
			ud = (UsingDeclaration)cu.Children.ElementAt(2);
			Assert.AreEqual("a::b.c", ud.Namespace);
		}
开发者ID:95ulisse,项目名称:ILEdit,代码行数:26,代码来源:UsingDeclarationTests.cs

示例3: UsingAliasDeclarationTest

		public void UsingAliasDeclarationTest()
		{
			string program = "using TESTME=System;\n" +
				"using myAlias=My.Name.Space;\n" +
				"using StringCollection = System.Collections.Generic.List<string>;\n";
			CSharpParser parser = new CSharpParser();
			CompilationUnit cu = parser.Parse(new StringReader(program));
			Assert.IsFalse(parser.HasErrors);
			
			Assert.AreEqual(3, cu.Children.Count());
			
			Assert.IsTrue(cu.Children.ElementAt(0) is UsingAliasDeclaration);
			UsingAliasDeclaration ud = (UsingAliasDeclaration)cu.Children.ElementAt(0);
			Assert.AreEqual("TESTME", ud.Alias);
			Assert.AreEqual("System", ud.Import.ToString());
			
			Assert.IsTrue(cu.Children.ElementAt(1) is UsingAliasDeclaration);
			ud = (UsingAliasDeclaration)cu.Children.ElementAt(1);
			Assert.AreEqual("myAlias", ud.Alias);
			Assert.AreEqual("My.Name.Space", ud.Import.ToString());
			
			Assert.IsTrue(cu.Children.ElementAt(2) is UsingAliasDeclaration);
			ud = (UsingAliasDeclaration)cu.Children.ElementAt(2);
			Assert.AreEqual("StringCollection", ud.Alias);
			Assert.AreEqual("System.Collections.Generic.List<string>", ud.Import.ToString());
		}
开发者ID:95ulisse,项目名称:ILEdit,代码行数:26,代码来源:UsingDeclarationTests.cs

示例4: WrongUsingTest

		public void WrongUsingTest()
		{
			string program = "using\n";
			CSharpParser parser = new CSharpParser();
			CompilationUnit cu = parser.Parse(new StringReader(program));
			Assert.AreEqual(0, cu.Children.Count());
			Assert.IsTrue(parser.HasErrors);
		}
开发者ID:95ulisse,项目名称:ILEdit,代码行数:8,代码来源:UsingDeclarationTests.cs

示例5: ParseTestCase

		internal static IProjectContent ParseTestCase()
		{
			const string fileName = "TypeSystemTests.TestCase.cs";
			
			CSharpParser parser = new CSharpParser();
			CompilationUnit cu;
			using (Stream s = typeof(TypeSystemTests).Assembly.GetManifestResourceStream(typeof(TypeSystemTests), fileName)) {
				cu = parser.Parse(s);
			}
			
			var testCasePC = new SimpleProjectContent();
			CSharpParsedFile parsedFile = new TypeSystemConvertVisitor(testCasePC, fileName).Convert(cu);
			parsedFile.Freeze();
			testCasePC.UpdateProjectContent(null, parsedFile);
			return testCasePC;
		}
开发者ID:jiguixin,项目名称:ILSpy,代码行数:16,代码来源:TypeSystemConvertVisitorTests.cs

示例6: WrongUsingTest

		public void WrongUsingTest()
		{
			string program = "using\n";
			CSharpParser parser = new CSharpParser();
			SyntaxTree syntaxTree = parser.Parse (program);
			Assert.AreEqual(0, syntaxTree.Children.Count());
			Assert.IsTrue(parser.HasErrors);
		}
开发者ID:Gobiner,项目名称:ILSpy,代码行数:8,代码来源:UsingDeclarationTests.cs

示例7: ParseAndCheckPositions

		public void ParseAndCheckPositions()
		{
			CSharpParser parser = new CSharpParser();
			foreach (string fileName in fileNames) {
				var currentDocument = new ReadOnlyDocument(File.ReadAllText(fileName));
				SyntaxTree syntaxTree = parser.Parse(currentDocument, fileName);
				if (parser.HasErrors)
					continue;
				ConsistencyChecker.CheckPositionConsistency(syntaxTree, fileName, currentDocument);
				ConsistencyChecker.CheckMissingTokens(syntaxTree, fileName, currentDocument);
			}
		}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:12,代码来源:ParseSelfTests.cs

示例8: ParseTestCase

		internal static IProjectContent ParseTestCase()
		{
			const string fileName = "TypeSystemTests.TestCase.cs";
			
			CSharpParser parser = new CSharpParser();
			SyntaxTree syntaxTree;
			using (Stream s = typeof(TypeSystemTests).Assembly.GetManifestResourceStream(typeof(TypeSystemTests), fileName)) {
				syntaxTree = parser.Parse(s, fileName);
			}
			
			return CreateContent(syntaxTree.ToTypeSystem());
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:12,代码来源:TypeSystemConvertVisitorTests.cs

示例9: AssemblyAndModuleAttributesDoNotAppearOnTypes

        public void AssemblyAndModuleAttributesDoNotAppearOnTypes()
        {
            var parser = new CSharpParser();
            var cu = parser.Parse("[assembly: My1][module: My2][My3]class C {} public class My1Attribute : System.Attribute {} public class My2Attribute : System.Attribute {} public class My3Attribute : System.Attribute {}", "File.cs");

            var ts = cu.ToTypeSystem();
            var compilation = new CSharpProjectContent()
                .UpdateProjectContent(null, ts)
                .AddAssemblyReferences(new[] { CecilLoaderTests.Mscorlib })
                .CreateCompilation();
            var type = ReflectionHelper.ParseReflectionName("C").Resolve(compilation).GetDefinition();
            Assert.That(type.Attributes.Select(a => a.AttributeType.FullName).ToList(), Is.EqualTo(new[] { "My3Attribute" }));
        }
开发者ID:segaman,项目名称:NRefactory,代码行数:13,代码来源:TypeSystemConvertVisitorTests.cs

示例10: ParseAndCheckPositions

		public void ParseAndCheckPositions()
		{
			CSharpParser parser = new CSharpParser();
			foreach (string fileName in fileNames) {
				this.currentDocument = new ReadOnlyDocument(File.ReadAllText(fileName));
				CompilationUnit cu = parser.Parse(currentDocument.CreateReader(), fileName);
				if (parser.HasErrors)
					continue;
				this.currentFileName = fileName;
				CheckPositionConsistency(cu);
				CheckMissingTokens(cu);
			}
		}
开发者ID:KAW0,项目名称:Alter-Native,代码行数:13,代码来源:ParseSelfTests.cs

示例11: GenerateTypeSystem

		public void GenerateTypeSystem()
		{
			SimpleProjectContent pc = new SimpleProjectContent();
			CSharpParser parser = new CSharpParser();
			parser.GenerateTypeSystemMode = true;
			foreach (string fileName in fileNames) {
				CompilationUnit cu;
				using (var fs = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, FileOptions.SequentialScan)) {
					cu = parser.Parse(fs);
				}
				TypeSystemConvertVisitor cv = new TypeSystemConvertVisitor(pc, fileName);
				pc.UpdateProjectContent(null, cv.Convert(cu));
			}
		}
开发者ID:jiguixin,项目名称:ILSpy,代码行数:14,代码来源:ParseSelfTests.cs

示例12: ParseTestCase

		internal static IProjectContent ParseTestCase()
		{
			const string fileName = "TypeSystemTests.TestCase.cs";
			
			CSharpParser parser = new CSharpParser();
			SyntaxTree syntaxTree;
			using (Stream s = typeof(TypeSystemTests).Assembly.GetManifestResourceStream(typeof(TypeSystemTests), fileName)) {
				syntaxTree = parser.Parse(s, fileName);
			}
			
			var unresolvedFile = syntaxTree.ToTypeSystem();
			return new CSharpProjectContent()
				.AddOrUpdateFiles(unresolvedFile)
				.AddAssemblyReferences(new[] { CecilLoaderTests.Mscorlib })
				.SetAssemblyName(typeof(TypeSystemTests).Assembly.GetName().Name);
		}
开发者ID:Gobiner,项目名称:ILSpy,代码行数:16,代码来源:TypeSystemConvertVisitorTests.cs

示例13: FixtureSetUp

        public void FixtureSetUp()
        {
            const string fileName = "TypeSystemTests.TestCase.cs";

            CSharpParser parser = new CSharpParser();
            CompilationUnit cu;
            using (Stream s = typeof(TypeSystemTests).Assembly.GetManifestResourceStream(typeof(TypeSystemTests), fileName)) {
                cu = parser.Parse(s);
            }

            testCasePC = new SimpleProjectContent();
            TypeSystemConvertVisitor visitor = new TypeSystemConvertVisitor(testCasePC, fileName);
            cu.AcceptVisitor(visitor, null);
            ParsedFile parsedFile = visitor.ParsedFile;
            ((SimpleProjectContent)testCasePC).UpdateProjectContent(null, parsedFile.TopLevelTypeDefinitions, null, null);
        }
开发者ID:richardschneider,项目名称:ILSpy,代码行数:16,代码来源:TypeSystemConvertVisitorTests.cs

示例14: ConditionalSymbolTest

 public void ConditionalSymbolTest()
 {
     const string program = @"// Test
     #if AAA
     #undef AAA
     #define CCC
     #else
     #define DDD
     #endif
     class C {}";
     CSharpParser parser = new CSharpParser();
     parser.CompilerSettings.ConditionalSymbols.Add("AAA");
     parser.CompilerSettings.ConditionalSymbols.Add("BBB");
     var syntaxTree = parser.Parse(program, "elif.cs");
     Assert.AreEqual(new[] { "BBB", "CCC" }, syntaxTree.ConditionalSymbols);
 }
开发者ID:porcus,项目名称:NRefactory,代码行数:16,代码来源:PreprocessorDirectiveTests.cs

示例15: ParseTestCase

		internal static IProjectContent ParseTestCase()
		{
			const string fileName = "TypeSystemTests.TestCase.cs";
			
			CSharpParser parser = new CSharpParser();
			CompilationUnit cu;
			using (Stream s = typeof(TypeSystemTests).Assembly.GetManifestResourceStream(typeof(TypeSystemTests), fileName)) {
				cu = parser.Parse(s, fileName);
			}
			
			var parsedFile = cu.ToTypeSystem();
			return new CSharpProjectContent()
				.UpdateProjectContent(null, parsedFile)
				.AddAssemblyReferences(new[] { CecilLoaderTests.Mscorlib })
				.SetAssemblyName(typeof(TypeSystemTests).Assembly.GetName().Name);
		}
开发者ID:mono-soc-2012,项目名称:NRefactory,代码行数:16,代码来源:TypeSystemConvertVisitorTests.cs


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