It seems like it'd be a common requirement, but I cannot find a solution to this anywhere.
I have a method which will OrderBy
a collection depending on a parameter passed to it.
I'd like to pass the contents of an 'OrderBy' to the method, but cannot work out how to do it.
What I've Tried
I've tried a switch with a string (i.e. if you pass 'Name' it'll hit the case
which orders it by name), but this feels 'hacky' and unnecessary.
I know it's something like Func<TEntity, TResult>
, but I can't quite crack it.
PSEUDO CODE:
GetOrderedCollection([NOT SURE] orderBy)
{
return collection.OrderBy(orderBy);
}
Does this satisfy your requirements?