Unfortunately, you must have a matcher of the appropriate type.
You can create your own IComparer<object>
class that just completes the DateTime mapping, but there is no way to do this directly using broadcast.
If your collection always contains DateTime objects, you can simply do:
ICollection<DateTime> collection = ...;
collection.Sort(Comparer<DateTime>.Default);
Edit after reading the comment:
If you are working with ICollection directly, you can use the LINQ option:
collection.Cast<DateTime>().OrderBy( date => date );
If you are working with something that implements IList<T>
(for example List<DateTime>
), you can simply call Sort () on the list itself.
Since you are using a non-standard class, you need to make your own comparator:
class Comparer : IComparer<object> {
int Compare(object a, object b) {
return DateTime.Compare((DateTime)a, (DateTime)b);
}
}
Then you can call:
collection.Sort(new Comparer() );
source
to share