J
JV
I need to implement a method that processes two objects. Among other things,
the method may want to try to compare the two objects, which should use the
CompareTo method, provided the two objects are the same class and the class
implements IComparable<T>.
void process(object o1, object o2)
{
if (o1.GetType().Equals(o2.GetType()))
{
Type t = o1.GetType();
if t implements IComparable<T> where T is not known then ???
compare o1 and o2 using their CompareTo method ???
}
}
I specifically do not want the objects to implement the non-generic
IComparable version.
How can I check the type if it implements IComparable<T> and if so, how
could I then call the CompareTo method?
the method may want to try to compare the two objects, which should use the
CompareTo method, provided the two objects are the same class and the class
implements IComparable<T>.
void process(object o1, object o2)
{
if (o1.GetType().Equals(o2.GetType()))
{
Type t = o1.GetType();
if t implements IComparable<T> where T is not known then ???
compare o1 and o2 using their CompareTo method ???
}
}
I specifically do not want the objects to implement the non-generic
IComparable version.
How can I check the type if it implements IComparable<T> and if so, how
could I then call the CompareTo method?