Why is the Xamarin generated Java.Util.Date not IComparable

118 views Asked by At

I am fairly new to C# and Xamarin so hopefully this is something that is an easy answer.

I found myself in need of a reflective comparison method which could run over a varied bucked of objects. I based my solution off of the accepted answer in this question. Since I needed to be able to handle more than strict equality and use comparison operators if available, I added the following check

if (firstValue is System.IComparable)
{
    System.IComparable f = firstValue as System.IComparable;
    System.IComparable s = secondValue as System.IComparable;
...

so that I might be able to utilize the CompareTo method to know more than equality.

This works great for things such as numeric values, but it does not for the Xamarin generated Java.Util.Date and I would like some insight as to why.

namespace Java.Util
{
    public class Date : Object, ISerializable, ICloneable, IComparable, IJavaObject, IDisposable
    {
        ... 
        public virtual int CompareTo(Date date);
        ...
    }
}

From the definition of the is operator in the C# reference, it seems like this is exactly the case where is should evaluate to true.

I have checked and the IComparable that Java.Util.Date is implementing is System.IComparable.

I currently have a work around where I just call this method recursively on dates, but that is just a hack around my confusion.

Thank you for your help!

0

There are 0 answers