I have a
List<MyObjecT>
that I would like to be able to sort at run-time. I wanto to do this, without the giant
IF
statement
private List<Customer> SortCustomer(string sortBy, string sortOrder)
{
var myList = new List<Customer>();
if (sortBy == "firstname" && sortOrder == "asc") {
return myList.OrderBy(x => x.FirstName);
} else if (sortBy == "firstname" && sortOrder == "desc") {
return myList.OrderByDesc(x => x.firstName);
} else if .....
}
I can't sort in the database easily (one of the fields is a decimal stored as string, another is a lookup field, but there's no lookup table so in the database it is just an int field with no reference. I didn't want to deal with trying to convert the db fields as necessary to sort.
I also can't use the Dynamic Linq Library, just to make things more complicated.
Any ideas?
Thanks,
Andrew