Skip to content

Commit

Permalink
Improve ordering in target framework dropdown
Browse files Browse the repository at this point in the history
Previously the ordering was "natural" ascending. This created a block with ".NET 5+" items at the top, and ".NET Core" items below, however the newest .NET item (e.g. ".NET 9") would be in the middle of the list.

The change here adds sorting by group, then by version, and makes that version ordering descending. This means that the latest and greatest version is always at the top of the list.
  • Loading branch information
drewnoakes committed Oct 21, 2024
1 parent 2ef8923 commit c6f6ab9
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 c6f6ab9

Please sign in to comment.