@@ -141,7 +141,7 @@ usings[0].Parent is NamespaceDeclarationSyntax namespaceDeclarationSyntax
141141 return Doc . Concat ( docs ) ;
142142 }
143143
144- private static IEnumerable < List < UsingData > > GroupUsings (
144+ private static IEnumerable < IEnumerable < UsingData > > GroupUsings (
145145 List < UsingDirectiveSyntax > usings ,
146146 SyntaxTriviaList triviaOnFirstUsing ,
147147 PrintingContext context
@@ -182,6 +182,8 @@ PrintingContext context
182182 {
183183 Using = usingDirective ,
184184 LeadingTrivia = PrintLeadingTrivia ( usingDirective ) ,
185+ Alias = usingDirective ? . Alias ? . ToFullString ( ) ,
186+ Name = usingDirective ? . Name ? . ToFullString ( ) ,
185187 }
186188 ) ;
187189 }
@@ -198,6 +200,8 @@ PrintingContext context
198200 {
199201 Using = usingDirective ,
200202 LeadingTrivia = ! openIf ? PrintLeadingTrivia ( usingDirective ) : Doc . Null ,
203+ Alias = usingDirective ? . Alias ? . ToFullString ( ) ,
204+ Name = usingDirective ? . Name ? . ToFullString ( ) ,
201205 } ;
202206
203207 if ( usingDirective . GlobalKeyword . RawSyntaxKind ( ) != SyntaxKind . None )
@@ -245,15 +249,15 @@ PrintingContext context
245249 }
246250 }
247251
248- yield return globalSystemUsings . OrderBy ( o => o . Using , Comparer ) . ToList ( ) ;
249- yield return globalUsings . OrderBy ( o => o . Using , Comparer ) . ToList ( ) ;
250- yield return globalAliasUsings . OrderBy ( o => o . Using , Comparer ) . ToList ( ) ;
251- yield return systemUsings . OrderBy ( o => o . Using , Comparer ) . ToList ( ) ;
252- yield return aliasNameUsings . OrderBy ( o => o . Using , Comparer ) . ToList ( ) ;
253- yield return regularUsings . OrderBy ( o => o . Using , Comparer ) . ToList ( ) ;
254- yield return staticSystemUsings . OrderBy ( o => o . Using , Comparer ) . ToList ( ) ;
255- yield return staticUsings . OrderBy ( o => o . Using , Comparer ) . ToList ( ) ;
256- yield return aliasUsings . OrderBy ( o => o . Using , Comparer ) . ToList ( ) ;
252+ yield return globalSystemUsings . OrderBy ( o => o , Comparer ) ;
253+ yield return globalUsings . OrderBy ( o => o , Comparer ) ;
254+ yield return globalAliasUsings . OrderBy ( o => o , Comparer ) ;
255+ yield return systemUsings . OrderBy ( o => o , Comparer ) ;
256+ yield return aliasNameUsings . OrderBy ( o => o , Comparer ) ;
257+ yield return regularUsings . OrderBy ( o => o , Comparer ) ;
258+ yield return staticSystemUsings . OrderBy ( o => o , Comparer ) ;
259+ yield return staticUsings . OrderBy ( o => o , Comparer ) ;
260+ yield return aliasUsings . OrderBy ( o => o , Comparer ) ;
257261 // we need the directive groups at the end, the #endif directive
258262 // will be attached to the first node after the usings making it very hard print it before any of these other groups
259263 yield return directiveGroup ;
@@ -274,6 +278,8 @@ private class UsingData
274278 {
275279 public Doc LeadingTrivia { get ; init ; } = Doc . Null ;
276280 public UsingDirectiveSyntax ? Using { get ; init ; }
281+ public string ? Alias { get ; init ; }
282+ public string ? Name { get ; init ; }
277283 }
278284
279285 private static bool IsSystemName ( NameSyntax value )
@@ -286,9 +292,9 @@ private static bool IsSystemName(NameSyntax value)
286292 return value is IdentifierNameSyntax { Identifier . Text : "System" } ;
287293 }
288294
289- private class DefaultOrder : IComparer < UsingDirectiveSyntax ? >
295+ private class DefaultOrder : IComparer < UsingData ? >
290296 {
291- public int Compare ( UsingDirectiveSyntax ? x , UsingDirectiveSyntax ? y )
297+ public int Compare ( UsingData ? x , UsingData ? y )
292298 {
293299 if ( x ? . Name is null && y ? . Name is not null )
294300 {
@@ -303,17 +309,15 @@ public int Compare(UsingDirectiveSyntax? x, UsingDirectiveSyntax? y)
303309 if ( x ? . Alias is not null && y ? . Alias is not null )
304310 {
305311 return string . Compare (
306- x . Alias . ToFullString ( ) ,
307- y . Alias . ToFullString ( ) ,
312+ x . Alias ,
313+ y . Alias ,
308314#pragma warning disable CA1309
309315 StringComparison . InvariantCultureIgnoreCase
310316#pragma warning restore CA1309
311317 ) ;
312318 }
313319
314- return string . Compare (
315- x ? . Name ? . ToFullString ( ) ,
316- y ? . Name ? . ToFullString ( ) ,
320+ return string . Compare ( x ? . Name , y ? . Name ,
317321#pragma warning disable CA1309
318322 StringComparison . InvariantCultureIgnoreCase
319323#pragma warning restore CA1309
0 commit comments