I have a table and i want to do sorting function for each column.
Sorting has two direction asc and desc.
1) How can i sort columns using reflection?
List<Person> GetSortedList(List<Person> persons, string direction, string column)
{
return persons.OrderBy(x => GetProperyByName(x, column)); //GetPropertyByName - ??
}
2) Also i want to do something what i can call chain of linq operators:
List<Person> GetSortedList(List<Person> persons, string direction, string column)
{
var linqChain;
if(direction=="up")
{
linqChain+=persons.OrderBy(x => GetProperyByName(x, column))
}
else
{
linqChain+=persons.OrderByDescending(x => GetProperyByName(x, column))
}
linqChain+=.Where(....);
return linqChain.Execute();
}
1) If you want to sort using string names of columns, use the Dynamic LINQ library.
2) You can concatenate LINQ expressions together by using an expression object.