I have an ObservableCollection, which consists of objects from a base type and derived type both.
public class BaseClass
{
public string First{get;set}
public ObservableCollection<BaseClass> Items {get;set}
}
public class DerivedClass : BaseClass
{
public Second{get;set}
}
the usage is with:
ObservableCollection<BaseClass> MyList;
MyList.Add(new BaseClass());
MyList.Add(new DerivedClass());
The requirement is to sort this collection on different properties, so to avoid "switch case" I have used dyanmic orderBy, as in:
MyList = new ObservableCollection<BaseClass>(MyList.AsQueryable().OrderBy(field));
MyList is actually a tree, and the sort is called recursively for ~1,000,000 items total, so performance is crucial here. I understood the dynamic orderBy is faster that reflection - getting property value for field name and comparing it. (or am I wrong?!?)
Now the problem is some properties exist in the derived type, but not in base, so sort is not performed correctly. How can I implement some comparer to handle missing fields as null/empty?