• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# CSharpParser类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



CSharpParser类属于命名空间,在下文中一共展示了CSharpParser类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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


示例16: OverloadResolutionWorks

        public void OverloadResolutionWorks()
        {
            var expression = "string.Join(\",\", new[]{2, 5})";
            var result = new CSharpParser().Parse(expression);

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

            ExpressionHelper.Check(expression, result);
            Assert.AreEqual(Common.CodeType.Method, intChunk.CodeType);
            Assert.AreEqual("string string.Join<int>(string separator, System.Collections.Generic.IEnumerable<int> values)", intChunk.TooltipValue);
        }
开发者ID:lukas-lansky,项目名称:CSharpFormatting,代码行数:11,代码来源:MethodDiscoveryTest.cs


示例17: SimpleMethodIsMarkedAsMethod

        public void SimpleMethodIsMarkedAsMethod()
        {
            var expression = "string.Join(\",\", new[]{\"a\", \"b\"})";
            var result = new CSharpParser().Parse(expression);

            var intChunk = result.TextChunks.First(ch => ch.TextValue == "Join");
            
            ExpressionHelper.Check(expression, result);
            Assert.AreEqual(Common.CodeType.Method, intChunk.CodeType);
            Assert.AreEqual("string string.Join(string separator, params string[] value)", intChunk.TooltipValue);
        }
开发者ID:lukas-lansky,项目名称:CSharpFormatting,代码行数:11,代码来源:MethodDiscoveryTest.cs


示例18: ItemPropertyOfTupleIsDiscovered

        public void ItemPropertyOfTupleIsDiscovered()
        {
            var expression = "var t = System.Tuple.Create(1, 2, 3); System.Console.WriteLine(t.Item2);";
            var result = new CSharpParser().Parse(expression);

            var propertyChunk = result.TextChunks.First(ch => ch.TextValue == "Item2");
            
            ExpressionHelper.Check(expression, result);
            Assert.AreEqual(Common.CodeType.Property, propertyChunk.CodeType);
            Assert.AreEqual("System.Tuple<int, int, int>.Item2", propertyChunk.TooltipValue);
        }
开发者ID:lukas-lansky,项目名称:CSharpFormatting,代码行数:11,代码来源:PropertyDiscoveryTest.cs


示例19: VarType

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

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

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


示例20: NamespaceInUsingIsRecognized

        public void NamespaceInUsingIsRecognized()
        {
            var expression = "using System.Collections.Generic;";
            var result = new CSharpParser().Parse(expression);

            var namespaceChunk = result.TextChunks.First(ch => ch.TextValue == "Generic");
            
            ExpressionHelper.Check(expression, result);
            Assert.AreEqual(Common.CodeType.Namespace, namespaceChunk.CodeType);
            Assert.AreEqual("System.Collections.Generic", namespaceChunk.TooltipValue);
        }
开发者ID:lukas-lansky,项目名称:CSharpFormatting,代码行数:11,代码来源:NamespaceDiscoveryTest.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# CSharpSyntaxNode类代码示例发布时间:2022-05-24
下一篇:
C# CSharpParseOptions类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap