I have a helper function, which basically calls CompareTo on two objects, but does some special corner case checking, converting, etc.
Originally I wrote the function as such:
public static bool BetterCompare(IComparable lhs, IComparable rhs, out retCode)
{
...
retCode = lhs.CompareTo(rhs);
...
}
But the problem is that if I have a class AwesomeClass : IComparable<AwesomeClass>
. In fact I have several as some older IComparable
classes have gone IComparable<T>
. Yet the compiler gets angry because it can't convert these new objects to IComparable
. I don't know if this makes it worse, but some of them are abstract
(though the abstract class does provide an implementation).
How can I convey "I want two objects that I can call CompareTo on" and not have the compiler give me any lip. Preferably, the new function should NOT look like BetterCompare<AwesomeClass>(this, that, out retCode);
, but just "do the right thing". Or is there a better way to do this without touching every class making them both IComparable
and IComparable<T>
?