New to F# Have a list of objects. Objects share the same base class, but the timestamp attribute we want to order by is not present on the base class. Every object in the list will have the timestamp attribute.
Requirement is to order the objects by the timestamp descending.
Attempted
let sortedList = unsortedList.Sort();
This results in
System.InvalidOperationException: Failed to compare two elements in the array. ---> System.ArgumentException: At least one object must implement IComparable. at System.Collections.Comparer.Compare(Object a, Object b)
You didn't post code so I can't give you the exact code to solve it.
Typically you will have a property in the Base Class or alternatively in an Interface, but let's suppose you have this:
And you can't touch that code. Then what you can do is this:
Using reflection is another possibility (see Mau's answer).
If you post a code sample I can give you a more specific solution and test it.