Ejemplo n.º 1
0
        public static async Task <Document> SplitAsync(
            Document document,
            MemberDeclarationSyntax member,
            AttributeListSyntax[] attributeLists,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            SyntaxNode root = await document.GetSyntaxRootAsync(cancellationToken).ConfigureAwait(false);

            SyntaxList <AttributeListSyntax> lists = member.GetAttributeLists();

            var newLists = new List <AttributeListSyntax>();

            int index = lists.IndexOf(attributeLists[0]);

            for (int i = 0; i < index; i++)
            {
                newLists.Add(lists[i]);
            }

            newLists.AddRange(attributeLists.SelectMany(f => AttributeRefactoring.SplitAttributes(f)));

            for (int i = index + attributeLists.Length; i < lists.Count; i++)
            {
                newLists.Add(lists[i]);
            }

            SyntaxNode newRoot = root.ReplaceNode(
                member,
                member.SetAttributeLists(newLists.ToSyntaxList()));

            return(document.WithSyntaxRoot(newRoot));
        }
        public static Task <Document> SplitAsync(
            Document document,
            MemberDeclarationSyntax member,
            AttributeListSyntax[] attributeLists,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            SyntaxList <AttributeListSyntax> lists = member.GetAttributeLists();

            var newLists = new List <AttributeListSyntax>();

            int index = lists.IndexOf(attributeLists[0]);

            for (int i = 0; i < index; i++)
            {
                newLists.Add(lists[i]);
            }

            newLists.AddRange(attributeLists.SelectMany(f => AttributeRefactoring.SplitAttributes(f)));

            for (int i = index + attributeLists.Length; i < lists.Count; i++)
            {
                newLists.Add(lists[i]);
            }

            return(document.ReplaceNodeAsync(
                       member,
                       member.SetAttributeLists(newLists.ToSyntaxList()),
                       cancellationToken));
        }
 public static Task <Document> RefactorAsync(
     Document document,
     AttributeListSyntax attributeList,
     CancellationToken cancellationToken)
 {
     return(document.ReplaceNodeAsync(
                attributeList,
                AttributeRefactoring.SplitAttributes(attributeList).Select(f => f.WithFormatterAnnotation()),
                cancellationToken));
 }