Beispiel #1
0
 internal static SyntaxList <UsingDirectiveSyntax> Sort(SyntaxList <UsingDirectiveSyntax> directives) =>
 SyntaxFactory.List(
     directives.
     OrderBy(x => x.StaticKeyword.IsKind(SyntaxKind.StaticKeyword) ? 1 : x.Alias == null ? 0 : 2).
     ThenBy(x => x.Alias?.ToString()).
     ThenBy(x => x.Name.ToString())
     .Distinct(new AutoRest.Core.Utilities.EqualityComparer <UsingDirectiveSyntax>((a, b) => a.Name.ToString() == b.Name.ToString(), a => 0)));
Beispiel #2
0
            public static T ProcessAttributes <T>(SyntaxList <AttributeListSyntax> attributes, Func <SyntaxList <AttributeListSyntax>, T> withAttributeLists)
            {
                var newAttributeList = attributes.OrderBy(l => AttributeOrdering(l.Attributes.First())).AsEnumerable();
                // Hack the whitespace together so it displays properly; we reordered the attributes but want to make sure the whitespace between still makes sense
                int i = 0;

                newAttributeList = newAttributeList.Select(x => x.WithTriviaFrom(attributes.ElementAt(i++)));
                var lists = SyntaxFactory.List <AttributeListSyntax>(newAttributeList);

                return(withAttributeLists(lists));
            }
Beispiel #3
0
        private SyntaxList <UsingDirectiveSyntax> SortUsings(SyntaxList <UsingDirectiveSyntax> usings)
        {
            // first check if already in order
            var inOrder = true;

            for (var i = 0; i < usings.Count - 1; ++i)
            {
                if (UsingDirectiveComparer.Instance.Compare(usings[i], usings[i + 1]) > 0)
                {
                    inOrder = false;
                    break;
                }
            }

            return(inOrder
                ? usings
                : new SyntaxList <UsingDirectiveSyntax>().AddRange(usings.OrderBy(n => n, UsingDirectiveComparer.Instance)));
        }
Beispiel #4
0
 private SyntaxList <MemberDeclarationSyntax> SortMembers(SyntaxList <MemberDeclarationSyntax> members)
 {
     return(members
            .OrderBy(f => f, _memberComparer)
            .ToSyntaxList());
 }