private static Task <Document> RefactorAsync( Document document, SingleLocalDeclarationStatementInfo localInfo, TypeSyntax type, StatementListInfo statementsInfo, CancellationToken cancellationToken) { LocalDeclarationStatementSyntax localStatement = localInfo.Statement; int index = statementsInfo.IndexOf(localStatement); VariableDeclaratorSyntax declarator = localInfo.Declarator; VariableDeclaratorSyntax newDeclarator = declarator.WithInitializer(null); VariableDeclarationSyntax newDeclaration = localInfo.Declaration.ReplaceNode(declarator, newDeclarator); if (type != null) { newDeclaration = newDeclaration.WithType(type.WithTriviaFrom(newDeclaration.Type)); } LocalDeclarationStatementSyntax newLocalStatement = localStatement .WithDeclaration(newDeclaration) .WithTrailingTrivia(NewLine()) .WithFormatterAnnotation(); ExpressionStatementSyntax assignmentStatement = SimpleAssignmentStatement(IdentifierName(localInfo.Identifier), localInfo.Initializer.Value) .WithTrailingTrivia(localStatement.GetTrailingTrivia()) .WithFormatterAnnotation(); StatementListInfo newStatementsInfo = statementsInfo .Insert(index + 1, assignmentStatement) .ReplaceAt(index, newLocalStatement); return(document.ReplaceStatementsAsync(statementsInfo, newStatementsInfo, cancellationToken)); }