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


C# CompilationUnitSyntax.ReplaceNode方法代码示例

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


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

示例1: FixGuidExportMetadata

		private static Task<Document> FixGuidExportMetadata(Document document, CompilationUnitSyntax root, ClassDeclarationSyntax classDeclaration, string guid)
		{
			var newSyntax = classDeclaration;
			
			newSyntax = newSyntax.ReplaceNode(
				newSyntax.GetAttributes("ExportMetadata").First(x => x.ArgumentList.Arguments[0].ToString() == "\"Guid\""),
				SyntaxFactory.Attribute(SyntaxFactory.ParseName("ExportMetadata"),
					SyntaxFactory.ParseAttributeArgumentList($"(\"Guid\", \"{guid}\")")));

			var newRoot = root.ReplaceNode(classDeclaration, newSyntax);
			var newDocument = document.WithSyntaxRoot(newRoot);
			return Task.FromResult(newDocument);
		}
开发者ID:batjoker,项目名称:KanColleViewer,代码行数:13,代码来源:InvalidGuidMetadataCodeFixProvider.cs

示例2: AddExport

		private static Task<Document> AddExport(Document document, CompilationUnitSyntax root, ClassDeclarationSyntax classDeclaration, string[] interfaceNames)
		{
			var newSyntax = classDeclaration;
			foreach (var interfaceName in interfaceNames)
			{
				var attributeList = SyntaxFactory.AttributeList(
					SyntaxFactory.SingletonSeparatedList(
						SyntaxFactory.Attribute(SyntaxFactory.ParseName("Export"),
							SyntaxFactory.ParseAttributeArgumentList($"(typeof({interfaceName}))"))));
				newSyntax = newSyntax.AddAttributeLists(attributeList);
			}
			var newRoot = root.ReplaceNode(classDeclaration, newSyntax);
			var newDocument = document.WithSyntaxRoot(newRoot);
			return Task.FromResult(newDocument);
		}
开发者ID:NatLee,项目名称:KanColleViewer,代码行数:15,代码来源:ExportCodeFixProvider.cs

示例3: AddInterface

		private static Task<Document> AddInterface(Document document, CompilationUnitSyntax root, ClassDeclarationSyntax classDeclaration, string[] interfaceNames)
		{
			var newSyntax = classDeclaration;
			foreach (var interfaceName in interfaceNames)
			{
				var baseType = SyntaxFactory.SimpleBaseType(SyntaxFactory.IdentifierName(interfaceName));
				newSyntax = newSyntax
					.AddBaseListTypes(baseType);
				newSyntax = newSyntax.ReplaceToken(newSyntax.Identifier,
					newSyntax.Identifier.WithTrailingTrivia(SyntaxFactory.Whitespace(" ")));
			}
			var newRoot = root.ReplaceNode(classDeclaration, newSyntax);
			var newDocument = document.WithSyntaxRoot(newRoot);
			return Task.FromResult(newDocument);
		}
开发者ID:NatLee,项目名称:KanColleViewer,代码行数:15,代码来源:ExportCodeFixProvider.cs

示例4: AddExportMetadata

		private static Task<Document> AddExportMetadata(Document document, CompilationUnitSyntax root, ClassDeclarationSyntax classDeclaration, string[] missingMetadata)
		{
			var newSyntax = classDeclaration;
			//値は空の状態で、必要なExportMetadataを全部追加
			foreach (var metadata in missingMetadata)
			{
				var attributeList = SyntaxFactory.AttributeList(
					SyntaxFactory.SingletonSeparatedList(
						SyntaxFactory.Attribute(SyntaxFactory.ParseName("ExportMetadata"),
							SyntaxFactory.ParseAttributeArgumentList($"(\"{metadata}\", \"\")"))));
				newSyntax = newSyntax.AddAttributeLists(attributeList);
			}
			var newRoot = root.ReplaceNode(classDeclaration, newSyntax);
			var newDocument = document.WithSyntaxRoot(newRoot);
			return Task.FromResult(newDocument);
		}
开发者ID:NatLee,项目名称:KanColleViewer,代码行数:16,代码来源:ExportMetadataCodeFixProvider.cs

示例5: NewCompilationFactory

        private static CompilationUnitSyntax NewCompilationFactory(CompilationUnitSyntax OldCompilation, ClassDeclarationSyntax OldClass, MethodDeclarationSyntax OldMethod)
        {
            var newNameSpace = OldCompilation;
            var className = $"NewClass{OldMethod.Identifier.Text}";
            var OldMemberNameSpace = (from member in OldCompilation.Members
                                      where member == OldClass
                                      select member).FirstOrDefault();
            newNameSpace = OldCompilation.ReplaceNode(OldMemberNameSpace, NewClassFactory(className, OldClass, OldMethod));
            var newParameterClass = NewClassParameterFactory(className, NewPropertyClassFactory(OldMethod));
            return newNameSpace.WithMembers(newNameSpace.Members.Add(newParameterClass))
                                .WithAdditionalAnnotations(Formatter.Annotation);

        }
开发者ID:nikolasmagno,项目名称:code-cracker,代码行数:13,代码来源:ParameterRefactoryCodeFixProvider.cs

示例6: ReplaceStaticCallWithExtionMethodCall

 private static CompilationUnitSyntax ReplaceStaticCallWithExtionMethodCall(CompilationUnitSyntax root, InvocationExpressionSyntax staticInvocationExpression, ExpressionSyntax sourceExpression, SimpleNameSyntax methodName, ArgumentListSyntax argumentList)
 {
     var extensionInvocationExpression = CallExtensionMethodAsExtensionAnalyzer.CreateInvocationExpression(sourceExpression, methodName, argumentList)
         .WithLeadingTrivia(staticInvocationExpression.GetLeadingTrivia());
     return root.ReplaceNode(staticInvocationExpression, extensionInvocationExpression);
 }
开发者ID:haroldhues,项目名称:code-cracker,代码行数:6,代码来源:CallExtensionMethodAsExtensionCodeFixProvider.cs

示例7: AddParameterClassToCompilationUnitAndUpdateClassToUseNamespace

 private static CompilationUnitSyntax AddParameterClassToCompilationUnitAndUpdateClassToUseNamespace(CompilationUnitSyntax oldCompilation, ClassDeclarationSyntax oldClass, MethodDeclarationSyntax oldMethod)
 {
     var className = $"NewClass{oldMethod.Identifier.Text}";
     var newParameterClass = CreateParameterClass(className, oldMethod);
     var newNamespace = oldCompilation.ReplaceNode(oldClass, UpdateClassToUseNewParameterClass(className, oldClass, oldMethod))
         .AddMembers(newParameterClass);
     return newNamespace;
 }
开发者ID:haroldhues,项目名称:code-cracker,代码行数:8,代码来源:ParameterRefactoryCodeFixProvider.cs

示例8: AddGuidExportMetadata

		private static Task<Document> AddGuidExportMetadata(Document document, CompilationUnitSyntax root, ClassDeclarationSyntax classDeclaration, string guid)
		{
			var newSyntax = classDeclaration;
			var attributeList = SyntaxFactory.AttributeList(
				SyntaxFactory.SingletonSeparatedList(
					SyntaxFactory.Attribute(SyntaxFactory.ParseName("ExportMetadata"),
						SyntaxFactory.ParseAttributeArgumentList($"(\"Guid\", \"{guid}\")"))));
			newSyntax = newSyntax.AddAttributeLists(attributeList);
			var newRoot = root.ReplaceNode(classDeclaration, newSyntax);
			var newDocument = document.WithSyntaxRoot(newRoot);
			return Task.FromResult(newDocument);
		}
开发者ID:Zcynical,项目名称:KanColleViewer,代码行数:12,代码来源:ExportGuidMetadataCodeFixProvider.cs

示例9: RewriteNotNestedInstance

        private static CompilationUnitSyntax RewriteNotNestedInstance(CompilationUnitSyntax root, MethodDeclarationSyntax originalCallingMethod, InvocationExpressionSyntax apmSyntax, BlockSyntax lambdaBlock, InvocationExpressionSyntax endStatement, string methodNameBase, Workspace workspace)
        {
            var taskName = FreeTaskName(originalCallingMethod);

            var awaitStatement = NewAwaitExpression(taskName);
            var rewrittenLambdaBlock = lambdaBlock.ReplaceNode(endStatement, awaitStatement);

            var newCallingMethod = RewriteOriginatingMethod(beginXxxCall, rewrittenLambdaBlock, methodNameBase, taskName);

            return root
                .ReplaceNode(originalCallingMethod, newCallingMethod)
                .WithUsingSystemThreadingTasks()
                .Format(workspace);
        }
开发者ID:modulexcite,项目名称:Asyncifier,代码行数:14,代码来源:CodeRefactoringProvider.cs


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