Exemple #1
0
        private static Task <Document> RefactorAsync(
            Document document,
            MemberDeclarationSelection selectedMembers,
            CancellationToken cancellationToken)
        {
            ImmutableArray <FieldInfo> fieldInfo = selectedMembers
                                                   .Select(member => ((FieldDeclarationSyntax)member).Declaration)
                                                   .SelectMany(declaration => declaration.Variables.Select(declarator => FieldInfo.Create(declaration.Type, declarator)))
                                                   .ToImmutableArray();

            return(RefactorAsync(document, fieldInfo, (TypeDeclarationSyntax)selectedMembers.ContainingMember, cancellationToken));
        }
        public static Task <Document> RefactorAsync(
            Document document,
            MemberDeclarationSelection selectedMembers,
            Accessibility newAccessibility,
            CancellationToken cancellationToken)
        {
            var members = (SyntaxList <MemberDeclarationSyntax>)selectedMembers.Items;

            SyntaxList <MemberDeclarationSyntax> newMembers = members
                                                              .Take(selectedMembers.StartIndex)
                                                              .Concat(selectedMembers.Select(f => f.WithAccessibility(newAccessibility)))
                                                              .Concat(members.Skip(selectedMembers.EndIndex + 1))
                                                              .ToSyntaxList();

            MemberDeclarationSyntax containingMember = selectedMembers.ContainingMember;

            MemberDeclarationSyntax newNode = containingMember.WithMembers(newMembers);

            return(document.ReplaceNodeAsync(containingMember, newNode, cancellationToken));
        }