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


C# CSharpParser类代码示例

本文整理汇总了C#中CSharpParser的典型用法代码示例。如果您正苦于以下问题:C# CSharpParser类的具体用法?C# CSharpParser怎么用?C# CSharpParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CSharpParser类属于命名空间,在下文中一共展示了CSharpParser类的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: ResolveCref

		public override IEntity ResolveCref(string cref)
		{
			if (cref.Length > 2 && cref[1] == ':') {
				// resolve ID string
				return base.ResolveCref(cref);
			}
			var documentationReference = new CSharpParser().ParseDocumentationReference(cref);
			var csharpContext = context as CSharpTypeResolveContext;
			CSharpResolver resolver;
			if (csharpContext != null) {
				resolver = new CSharpResolver(csharpContext);
			} else {
				resolver = new CSharpResolver(context.Compilation);
			}
			var astResolver = new CSharpAstResolver(resolver, documentationReference);
			var rr = astResolver.Resolve(documentationReference);
			
			MemberResolveResult mrr = rr as MemberResolveResult;
			if (mrr != null)
				return mrr.Member;
			TypeResolveResult trr = rr as TypeResolveResult;
			if (trr != null)
				return trr.Type.GetDefinition();
			return null;
		}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:25,代码来源:CSharpDocumentationComment.cs

示例5: Parse

		CSharpParsedFile Parse(string program)
		{
			CompilationUnit cu = new CSharpParser().Parse(new StringReader(program), "test.cs");
			CSharpParsedFile parsedFile = cu.ToTypeSystem();
			project = project.UpdateProjectContent(null, parsedFile);
			compilation = project.CreateCompilation();
			return parsedFile;
		}
开发者ID:KAW0,项目名称:Alter-Native,代码行数:8,代码来源:MemberLookupTests.cs

示例6: GlobalReferenceExpressionTest

 public void GlobalReferenceExpressionTest()
 {
     CSharpParser parser = new CSharpParser();
     parser.ParseTypeReference(new StringReader("global::System"));
     //Assert.IsTrue(tre.TypeReference.IsGlobal);
     //Assert.AreEqual("System", tre.TypeReference.Type);
     throw new NotImplementedException();
 }
开发者ID:richardschneider,项目名称:ILSpy,代码行数:8,代码来源:AliasReferenceExpressionTests.cs

示例7: 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

示例8: 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

示例9: GetCodeRoot

        public CodeRoot GetCodeRoot(string path)
        {
            if (File.Exists(path) == false)
                return null;

            CSharpParser formatter = new CSharpParser();
            formatter.ParseCode(File.ReadAllText(path));
            return (CodeRoot)formatter.CreatedCodeRoot;
        }
开发者ID:uQr,项目名称:Visual-NHibernate,代码行数:9,代码来源:Specs_For_CSharp_Code_Root_DiffTypes.cs

示例10: SingleLineCommentsAreDiscovered

        public void SingleLineCommentsAreDiscovered()
        {
            var expression = "var a = 1 + 3; // comment";
            var result = new CSharpParser().Parse(expression);
            
            var aChunk = result.TextChunks.First(ch => ch.TextValue == "// comment");

            ExpressionHelper.Check(expression, result);
            Assert.AreEqual(CodeType.Comment, aChunk.CodeType);
        }
开发者ID:lukas-lansky,项目名称:CSharpFormatting,代码行数:10,代码来源:CommentDiscoveryTest.cs

示例11: IfIsIdentifiedAsKeyword

        public void IfIsIdentifiedAsKeyword()
        {
            var expression = "if (System.Console.ReadLine() == \"a\") { System.Console.WriteLine(\"Oh!\"); }";
            var result = new CSharpParser().Parse(expression);

            var ifChunk = result.TextChunks.First(ch => ch.TextValue == "if");

            ExpressionHelper.Check(expression, result);
            Assert.AreEqual(Common.CodeType.Keyword, ifChunk.CodeType);
        }
开发者ID:lukas-lansky,项目名称:CSharpFormatting,代码行数:10,代码来源:KeywordDiscoveryTest.cs

示例12: VariableMentionType

        public void VariableMentionType()
        {
            var expression = "var a = 1 + 3; var b = a;";
            var result = new CSharpParser().Parse(expression);

            var aMention = result.TextChunks.Where(ch => ch.TextValue == "a").Skip(1).First();

            ExpressionHelper.Check(expression, result);
            Assert.AreEqual(CodeType.Variable, aMention.CodeType);
            Assert.AreEqual("struct System.Int32", aMention.TooltipValue);
        }
开发者ID:lukas-lansky,项目名称:CSharpFormatting,代码行数:11,代码来源:VariableTypeDiscoveryTest.cs

示例13: InitializationTypeType

        public void InitializationTypeType()
        {
            var expression = "var a = new System.Int32();";
            var result = new CSharpParser().Parse(expression);

            var intChunk = result.TextChunks.First(ch => ch.TextValue == "Int32");

            ExpressionHelper.Check(expression, result);
            Assert.AreEqual(CodeType.Type, intChunk.CodeType);
            Assert.AreEqual("struct System.Int32", intChunk.TooltipValue);
        }
开发者ID:lukas-lansky,项目名称:CSharpFormatting,代码行数:11,代码来源:TypeTypeDiscoveryTest.cs

示例14: DeclarationGenericTypeType

        public void DeclarationGenericTypeType()
        {
            var expression = "System.Tuple<int, int> a = System.Tuple.Create(1, 1);";
            var result = new CSharpParser().Parse(expression);
            
            var intChunk = result.TextChunks.First(ch => ch.TextValue == "Tuple");

            ExpressionHelper.Check(expression, result);
            Assert.AreEqual(CodeType.Type, intChunk.CodeType);
            Assert.AreEqual("class System.Tuple", intChunk.TooltipValue);
        }
开发者ID:lukas-lansky,项目名称:CSharpFormatting,代码行数:11,代码来源:TypeTypeDiscoveryTest.cs

示例15: DeclarationPredefinedTypeType

        public void DeclarationPredefinedTypeType()
        {
            var expression = "int a = 1 + 3;";
            var result = new CSharpParser().Parse(expression);

            var intChunk = result.TextChunks.First(ch => ch.TextValue == "int");

            ExpressionHelper.Check(expression, result);
            Assert.AreEqual(CodeType.Keyword, intChunk.CodeType);
            Assert.AreEqual("struct System.Int32", intChunk.TooltipValue);
        }
开发者ID:lukas-lansky,项目名称:CSharpFormatting,代码行数:11,代码来源:TypeTypeDiscoveryTest.cs


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