I would like to sort a common list in base class from its derived classes.
Each derived class sorts by a different property.
Therefore I use this idea: pass the relevant property to sort the base-class-list by.
protected void SortBy( Func<MyBaseClass, IComparable> getProp)
{
if (BaseClassList != null && BaseClassList .Count > 0)
{
BaseClassList = BaseClassList
.OrderBy(x => getProp(x))
.ToList();
}
}
And invoke it from derived classes by SortBy(x => x.GetTop);
Well, now I would like to sort by several properties; for each additional sent property, a ThenBy
expression should be added to the method body.
BaseClassList = BaseClassList
.OrderBy(x => getProp(x))
.ThenBy(x => x.getOtherProp)
.ToList();
Since I do not know how many properties will be sent I would like to use the params
idea.
However, I understand it is impossible since 'The parameter array must be a single dimensional array
'.
Any ideas?