I have a list which I need to order eg.
var list = someelements;
I also have a parameter which says by which property and what direction I should order list data eg.
var sortby = "Name";
var sortdirection = "desc";
I was wondering if I can match string property name with the right property so I get:
var list = someelements.OrderBy(x => x.Name).ToList();
when sortby == "Name"
without the need of using switch loop to check property name and assign a correct property to OrderBy.
Same I would like to achieve with select either OrderBy
or OrderByDescending
depending whether I get sortdirection = "asc"
or sortdirection = "desc"
Is it possible and if yes, how?