Skip to content

Commit

Permalink
Merge pull request #9566 from drewnoakes/order-target-frameworks-in-d…
Browse files Browse the repository at this point in the history
…ropdown

Improve ordering in target framework dropdown
  • Loading branch information
drewnoakes authored Oct 22, 2024
2 parents 2ef8923 + c6f6ab9 commit 2c072e3
Showing 1 changed file with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,29 @@ protected override IEnumValue ToEnumValue(KeyValuePair<string, IImmutableDiction

protected override int SortValues(IEnumValue a, IEnumValue b)
{
return NaturalStringComparer.Instance.Compare(a.DisplayName, b.DisplayName);
// Order by family first, then by version (descending).
int comparison = GetFamilyRank(a.DisplayName) - GetFamilyRank(b.DisplayName);

if (comparison is not 0)
{
// Ranks differ.
return comparison;
}

// Same rank. Large numbers first.
return NaturalStringComparer.Instance.Compare(a.DisplayName, b.DisplayName) * -1;

static int GetFamilyRank(string displayName)
{
if (displayName.StartsWith(".NET Core ", StringComparison.OrdinalIgnoreCase))
return 1;
if (displayName.StartsWith(".NET Standard ", StringComparison.OrdinalIgnoreCase))
return 2;
if (displayName.StartsWith(".NET Framework ", StringComparison.OrdinalIgnoreCase))
return 3;
if (displayName.StartsWith(".NET ", StringComparison.OrdinalIgnoreCase))
return 0;
return 4;
}
}
}

0 comments on commit 2c072e3

Please sign in to comment.