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)); }