public static Task <Document> RefactorAsync( Document document, LocalFunctionStatementSyntax localFunction, bool copyAfter = true, CancellationToken cancellationToken = default) { StatementListInfo statementsInfos = SyntaxInfo.StatementListInfo(localFunction); SyntaxList <StatementSyntax> statements = statementsInfos.Statements; int index = statements.IndexOf(localFunction); if (index == 0) { if (copyAfter) { if (statementsInfos.ParentAsBlock.OpenBraceToken.GetFullSpanEndLine() == localFunction.GetFullSpanStartLine()) { localFunction = localFunction.WithLeadingTrivia(localFunction.GetLeadingTrivia().Insert(0, NewLine())); } } else { localFunction = localFunction.WithTrailingTrivia(localFunction.GetTrailingTrivia().Add(NewLine())); } } int insertIndex = (copyAfter) ? index + 1 : index; SyntaxList <StatementSyntax> newStatements = statements.Insert(insertIndex, localFunction.WithNavigationAnnotation()); return(document.ReplaceStatementsAsync(statementsInfos, newStatements, cancellationToken)); }
public static Task <Document> RefactorAsync( Document document, LocalFunctionStatementSyntax localFunction, CancellationToken cancellationToken = default(CancellationToken)) { if (document == null) { throw new ArgumentNullException(nameof(document)); } if (localFunction == null) { throw new ArgumentNullException(nameof(localFunction)); } StatementsInfo statementsInfos = SyntaxInfo.StatementsInfo(localFunction); SyntaxList <StatementSyntax> statements = statementsInfos.Statements; int index = statements.IndexOf(localFunction); if (index == 0 && statementsInfos.Block.OpenBraceToken.GetFullSpanEndLine() == localFunction.GetFullSpanStartLine()) { localFunction = localFunction.WithLeadingTrivia(localFunction.GetLeadingTrivia().Insert(0, NewLine())); } SyntaxList <StatementSyntax> newStatements = statements.Insert(index + 1, localFunction.WithNavigationAnnotation()); return(document.ReplaceStatementsAsync(statementsInfos, newStatements, cancellationToken)); }