public static Task <Document> RefactorAsync( Document document, UsingStatementSyntax usingStatement, CancellationToken cancellationToken = default(CancellationToken)) { StatementContainer container = StatementContainer.Create(usingStatement); int index = container.Statements.IndexOf(usingStatement); StatementContainer newContainer = container.RemoveStatementAt(index); var statements = new List <StatementSyntax>() { SyntaxFactory.LocalDeclarationStatement(usingStatement.Declaration) }; statements.AddRange(GetStatements(usingStatement)); if (statements.Count > 0) { statements[0] = statements[0] .WithLeadingTrivia(usingStatement.GetLeadingTrivia()); statements[statements.Count - 1] = statements[statements.Count - 1] .WithTrailingTrivia(usingStatement.GetTrailingTrivia()); } newContainer = newContainer.WithStatements(newContainer.Statements.InsertRange(index, statements)); return(document.ReplaceNodeAsync(container.Node, newContainer.Node.WithFormatterAnnotation(), cancellationToken)); }