private static SyntaxRemoveOptions CreateSyntaxRemoveOptions( TLocalDeclarationStatement localDeclaration, IBlockFactsService blockFacts) { var removeOptions = SyntaxGenerator.DefaultRemoveOptions; if (localDeclaration != null) { if (localDeclaration.GetLeadingTrivia().Contains(t => t.IsDirective)) { removeOptions |= SyntaxRemoveOptions.KeepLeadingTrivia; } else { var statementParent = localDeclaration.Parent; if (blockFacts.IsExecutableBlock(statementParent)) { var siblings = blockFacts.GetExecutableBlockStatements(statementParent); var localDeclarationIndex = siblings.IndexOf(localDeclaration); if (localDeclarationIndex != 0) { // if we're removing the first statement in a block, then we // want to have the elastic marker on it so that the next statement // properly formats with the space left behind. But if it's // not the first statement then just keep the trivia as is // so that the statement before and after it stay appropriately // spaced apart. removeOptions &= ~SyntaxRemoveOptions.AddElasticMarker; } } } } return(removeOptions); }
private static bool TryGetSiblingStatement( ISyntaxFactsService syntaxFacts, IBlockFactsService blockFacts, SyntaxNode ifOrElseIf, int relativeIndex, out SyntaxNode statement) { if (syntaxFacts.IsExecutableStatement(ifOrElseIf) && blockFacts.IsExecutableBlock(ifOrElseIf.Parent)) { var blockStatements = blockFacts.GetExecutableBlockStatements(ifOrElseIf.Parent); statement = blockStatements.ElementAtOrDefault(blockStatements.IndexOf(ifOrElseIf) + relativeIndex); return(statement != null); } statement = null; return(false); }