Skip to content

Commit

Permalink
Sort import order
Browse files Browse the repository at this point in the history
  • Loading branch information
rkodev committed Sep 27, 2023
1 parent 2d5dcf7 commit 3807a43
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ public override void WriteCodeElement(CodeFileDeclaration codeElement, LanguageW

// remove duplicate using, keep a single using for each internal type in the same namespace
var enumeratedUsing = usings.ToArray();
var filteredUsing = enumeratedUsing.Where(x => x.IsExternal)
var filteredUsing = enumeratedUsing.Where(static x => x.IsExternal)
.Union(enumeratedUsing.ToArray()
.Where(x => x is { IsExternal: false, Declaration.TypeDefinition: not null })
.GroupBy(x =>
.Where(static x => x is { IsExternal: false, Declaration.TypeDefinition: not null })
.GroupBy(static x =>
$"{x.Declaration!.TypeDefinition!.GetImmediateParentOfType<CodeNamespace>().Name}.{x.Declaration?.Name.ToLowerInvariant()}")
.Select(x => x.First()));
.Select(static x => x.OrderBy(static x => x.Parent?.Name).First()));

_codeUsingWriter.WriteCodeElement(filteredUsing, ns, writer);
}
Expand Down

0 comments on commit 3807a43

Please sign in to comment.