我是相当新的通用编程,并有一个问题:通过特定属性的通用订购方法
我想按特定的属性,应该定义为参数排序列表。 请看代码为更好地了解我想要什么:
public static IEnumerable<T> SortEmployeesFor<T>(
IEnumerable<T> list,
property1,
property2,
OrderOptions options)
{
switch (options)
{
case OrderOptions.1:
return list.OrderBy(x => property1).ThenBy(x => property2);
case OrderOptions.2:
return list.OrderBy(x => property2).ThenBy(x => x.property1);
...
}
return list;
}
是否有执行此的任何选项?
P.S.这是我的第一篇文章,如果我做错了,请理解并让我知道。
什么property1和property2的类型? – Heisenbug