private async Task <Document> ChangetoAwaitAsync(Document document, InvocationExpressionSyntax invocation, string name, CancellationToken cancellationToken) { SyntaxNode oldExpression = invocation; SyntaxNode newExpression = null; if (!name.Contains("Async")) { var oldToken = invocation.DescendantTokens().First(z => z.Text == name); var newToken = SyntaxFactory.Identifier(oldToken.LeadingTrivia, SyntaxKind.IdentifierToken, name + "Async", name + "Async", oldToken.TrailingTrivia); var tempInvocation = invocation.ReplaceToken(oldToken, newToken); newExpression = SyntaxFactory.AwaitExpression(tempInvocation).WithAdditionalAnnotations(Formatter.Annotation); } var oldroot = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false); var newroot = oldroot.ReplaceNode(oldExpression, newExpression); var newDocument = document.WithSyntaxRoot(newroot); return(newDocument); }