public static async Task <Document> RefactorAsync( Document document, ElseClauseSyntax elseClause, CancellationToken cancellationToken) { if (elseClause.IsParentKind(SyntaxKind.IfStatement)) { var ifStatement = (IfStatementSyntax)elseClause.Parent; StatementSyntax statement = ifStatement.Statement; if (statement?.GetTrailingTrivia().IsEmptyOrWhitespace() == true) { IfStatementSyntax newIfStatement = ifStatement .WithStatement(statement.WithTrailingTrivia(elseClause.GetTrailingTrivia())) .WithElse(null); return(await document.ReplaceNodeAsync(ifStatement, newIfStatement, cancellationToken).ConfigureAwait(false)); } } return(await document.RemoveNodeAsync(elseClause, SyntaxRemoveOptions.KeepExteriorTrivia, cancellationToken).ConfigureAwait(false)); }