private static async Task <Document> RefactorAsync( Document document, ExpressionSyntax expression, SyntaxList <StatementSyntax> statements, StatementContainer container, int statementIndex, int lastStatementIndex, CancellationToken cancellationToken) { IEnumerable <StatementSyntax> blockStatements = statements .Skip(statementIndex + 1) .Take(lastStatementIndex - statementIndex); IfStatementSyntax ifStatement = CreateNullCheck(expression, List(blockStatements)); if (lastStatementIndex < statements.Count - 1) { ifStatement = ifStatement.AppendTrailingTrivia(NewLineTrivia()); } IEnumerable <StatementSyntax> newStatements = statements.Take(statementIndex + 1) .Concat(new IfStatementSyntax[] { ifStatement }) .Concat(statements.Skip(lastStatementIndex + 1)); return(await document.ReplaceNodeAsync(container.Node, container.NodeWithStatements(newStatements), cancellationToken).ConfigureAwait(false)); }