You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
NaturalStringComparer can't be passed where a non-generic IComparer is required (ArrayList.Sort, WPF CollectionView.CustomSort, WinForms ListView sorting) #74
NaturalStringComparer (Sorting/NaturalStringComparer.cs:16) implements only IComparer<string?>. Several common .NET sorting APIs accept only the non-generic System.Collections.IComparer, and sorting file names naturally is a typical reason to use them:
WPF: ListCollectionView.CustomSort, the usual way to sort a bound ListBox or DataGrid with custom logic
WinForms: ListView.ListViewItemSorter and DataGridView.Sort(IComparer)
ArrayList.Sort, Array.Sort(Array, IComparer) and the non-generic SortedList
None of these accept the comparer today, so every caller has to write their own adapter class.
Observed: the code doesn't compile: error CS1503: Argument 1: cannot convert from 'ktsu.Sorting.NaturalStringComparer' to 'System.Collections.IComparer?'. Also, new NaturalStringComparer() is IComparer evaluates to False.
Expected: it compiles and sorts the list to file1.txt, file2.txt, file10.txt.
Suggested fix
Implement System.Collections.IComparer alongside the generic interface. Either:
add an explicit int IComparer.Compare(object? x, object? y) that forwards to Compare(string?, string?), or
derive from Comparer<string?>, which provides both interfaces.
Adding an interface keeps source and binary compatibility. Re-run package validation either way, because this overlaps with #72 and #73.
Acceptance criteria
new NaturalStringComparer() can be passed anywhere a System.Collections.IComparer is expected.
Category: Feature Request. It's an API addition: support for the non-generic IComparer.
Priority: Low. Callers can work around it with a small adapter, and nothing is broken today. It is still a cheap win for WPF, WinForms and ArrayList users.
Area / suggested assignment:Sorting/NaturalStringComparer.cs. Whoever owns the comparer's public API should take it.
Duplicates / in progress: No duplicate found, and no open PR covers it. Related:
Next step: Add an explicit int IComparer.Compare(object?, object?) that forwards to the generic method. That keeps Compare_AllocatesNothing green; deriving from Comparer<string?> would also work but changes the base type. Add tests for ArrayList.Sort and for the wrong-type ArgumentException.
Activity
matt-edmondson commentedon Nov 2, 2026
Triage
IComparer.ArrayListusers.Sorting/NaturalStringComparer.cs. Whoever owns the comparer's public API should take it.CompatibilitySuppressions.xml. Land it first so that package validation shows only the API change from this issue.int IComparer.Compare(object?, object?)that forwards to the generic method. That keepsCompare_AllocatesNothinggreen; deriving fromComparer<string?>would also work but changes the base type. Add tests forArrayList.Sortand for the wrong-typeArgumentException.Generated by Claude Code