本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}