ErrorProne.NET icon indicating copy to clipboard operation
ErrorProne.NET copied to clipboard

Rule proposal: Warn (or error) when calling .Sort or .OrderBy against collections that don't implement IComparable<T>

Open R2D221 opened this issue 4 years ago • 0 comments

So, a while ago I found myself with a list of items, and the class Item implemented IComparable<T> for no apparent reason. So, I took the interface away, and when I tested it, it failed at runtime because at some point the list was getting sorted.

This should be a compile time error (why would you sort a list of non-sortable items), but we can make a rule in the analyzer instead.

The only instances I can think of of this happening are List<T>.Sort() and Enumerable.OrderBy()

R2D221 avatar Nov 21 '19 15:11 R2D221