Beispiel #1
0
        public static Task <Document> RefactorAsync(
            Document document,
            SwitchSectionSyntax switchSection,
            CancellationToken cancellationToken)
        {
            var switchStatement = (SwitchStatementSyntax)switchSection.Parent;

            SyntaxList <SwitchSectionSyntax> sections = switchStatement.Sections;

            SyntaxList <StatementSyntax> statements = MergeSwitchSectionsAnalyzer.GetStatementsOrDefault(switchSection);

            int index = sections.IndexOf(switchSection);

            int i = index + 1;

            while (i < sections.Count - 1 &&
                   !sections[i].SpanOrLeadingTriviaContainsDirectives() &&
                   AreEquivalent(statements, MergeSwitchSectionsAnalyzer.GetStatementsOrDefault(sections[i + 1])))
            {
                i++;
            }

            SyntaxList <SwitchSectionSyntax> newSections = sections
                                                           .ModifyRange(index, i - index, f => CreateSectionWithoutStatements(f))
                                                           .ToSyntaxList();

            SwitchStatementSyntax newSwitchStatement = switchStatement.WithSections(newSections);

            return(document.ReplaceNodeAsync(switchStatement, newSwitchStatement, cancellationToken));
        }
Beispiel #2
0
        private static Task <Document> RefactorAsync(
            Document document,
            MemberDeclarationListSelection selectedMembers,
            CancellationToken cancellationToken)
        {
            SyntaxList <MemberDeclarationSyntax> members = selectedMembers.UnderlyingList;

            IEnumerable <MemberDeclarationSyntax> newMembers = members.ModifyRange(
                selectedMembers.FirstIndex,
                selectedMembers.Count - 1,
                member => member.AppendToTrailingTrivia(CSharpFactory.NewLine()));

            MemberDeclarationListInfo membersInfo = SyntaxInfo.MemberDeclarationListInfo(selectedMembers);

            return(document.ReplaceMembersAsync(membersInfo, newMembers, cancellationToken));
        }