I have a generic class which could use a generic OrderBy argument
the class is as follows
class abc<T> where T : myType
{
public abc(....., orderBy_Argument ){ ... }
void someMethod(arg1, arg2, bool afterSort = false)
{
IEnumerable<myType> res ;
if ( afterSort && orderBy_Argument != null )
res = src.Except(tgt).OrderBy( .... );
else
res = src.Except(tgt);
}
}
The orderBy could be of various types
e.g.
.OrderBy( person => person.FirstName )
.OrderBy( person => person.LastName )
.OrderBy( person => person.LastName, caseInsensitive etc )
The goal is to make the orderBy an argument rather than bake it in
any ideas ?
Don’t pass in the arguments to
OrderBypass in a function which transforms anIEnumerable(orIQueryable, as it may be).Modifying your example to do so results in the following program:
Of course, this is a pretty weird ordering and a nonsensical
someMethod– but it demonstrates that you can pass in a very flexible sorting delegate (indeed, the delegate could do more than just sort) with only a very short implementation.