@@ -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 }
@@ -190,14 +192,21 @@ PrintingContext context
190192 if ( openIf )
191193 {
192194 directiveGroup . Add (
193- new UsingData { LeadingTrivia = PrintLeadingTrivia ( usingDirective ) }
195+ new UsingData
196+ {
197+ LeadingTrivia = PrintLeadingTrivia ( usingDirective ) ,
198+ Alias = usingDirective ? . Alias ? . ToFullString ( ) ,
199+ Name = usingDirective ? . Name ? . ToFullString ( ) ,
200+ }
194201 ) ;
195202 }
196203
197204 var usingData = new UsingData
198205 {
199206 Using = usingDirective ,
200207 LeadingTrivia = ! openIf ? PrintLeadingTrivia ( usingDirective ) : Doc . Null ,
208+ Alias = usingDirective ? . Alias ? . ToFullString ( ) ,
209+ Name = usingDirective ? . ToFullString ( ) ,
201210 } ;
202211
203212 if ( usingDirective . GlobalKeyword . RawSyntaxKind ( ) != SyntaxKind . None )
@@ -245,15 +254,15 @@ PrintingContext context
245254 }
246255 }
247256
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 ( ) ;
257+ yield return globalSystemUsings . OrderBy ( o => o , Comparer ) ;
258+ yield return globalUsings . OrderBy ( o => o , Comparer ) ;
259+ yield return globalAliasUsings . OrderBy ( o => o , Comparer ) ;
260+ yield return systemUsings . OrderBy ( o => o , Comparer ) ;
261+ yield return aliasNameUsings . OrderBy ( o => o , Comparer ) ;
262+ yield return regularUsings . OrderBy ( o => o , Comparer ) ;
263+ yield return staticSystemUsings . OrderBy ( o => o , Comparer ) ;
264+ yield return staticUsings . OrderBy ( o => o , Comparer ) ;
265+ yield return aliasUsings . OrderBy ( o => o , Comparer ) ;
257266 // we need the directive groups at the end, the #endif directive
258267 // will be attached to the first node after the usings making it very hard print it before any of these other groups
259268 yield return directiveGroup ;
@@ -274,6 +283,8 @@ private class UsingData
274283 {
275284 public Doc LeadingTrivia { get ; init ; } = Doc . Null ;
276285 public UsingDirectiveSyntax ? Using { get ; init ; }
286+ public string ? Alias { get ; init ; }
287+ public string ? Name { get ; init ; }
277288 }
278289
279290 private static bool IsSystemName ( NameSyntax value )
@@ -286,9 +297,9 @@ private static bool IsSystemName(NameSyntax value)
286297 return value is IdentifierNameSyntax { Identifier . Text : "System" } ;
287298 }
288299
289- private class DefaultOrder : IComparer < UsingDirectiveSyntax ? >
300+ private class DefaultOrder : IComparer < UsingData ? >
290301 {
291- public int Compare ( UsingDirectiveSyntax ? x , UsingDirectiveSyntax ? y )
302+ public int Compare ( UsingData ? x , UsingData ? y )
292303 {
293304 if ( x ? . Name is null && y ? . Name is not null )
294305 {
@@ -303,17 +314,17 @@ public int Compare(UsingDirectiveSyntax? x, UsingDirectiveSyntax? y)
303314 if ( x ? . Alias is not null && y ? . Alias is not null )
304315 {
305316 return string . Compare (
306- x . Alias . ToFullString ( ) ,
307- y . Alias . ToFullString ( ) ,
317+ x . Alias ,
318+ y . Alias ,
308319#pragma warning disable CA1309
309320 StringComparison . InvariantCultureIgnoreCase
310321#pragma warning restore CA1309
311322 ) ;
312323 }
313324
314325 return string . Compare (
315- x ? . Name ? . ToFullString ( ) ,
316- y ? . Name ? . ToFullString ( ) ,
326+ x ? . Name ,
327+ y ? . Name ,
317328#pragma warning disable CA1309
318329 StringComparison . InvariantCultureIgnoreCase
319330#pragma warning restore CA1309
0 commit comments