ErrorProne.NET
ErrorProne.NET copied to clipboard
Rule proposal: Warn (or error) when calling .Sort or .OrderBy against collections that don't implement IComparable<T>
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()