plina

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
public class QeurySort
    {
        public static IList<T> Sort<T>(IList<T> list,string sidx,string sord)
        {
            switch (sord)
            {
                case "asc":
                    return list.OrderBy(l => GetValue(l, sidx)).ToList();
                case "desc":
                    return list.OrderByDescending(l => GetValue(l, sidx)).ToList();
                default:
                    return list.OrderBy(l => GetValue(l, sidx)).ToList();
            }

        }

        public static object GetValue<T>(T model, string sidx)
        {
            return model.GetType().GetProperty(sidx).GetValue(model, null);
        }
    }

 

posted on 2016-11-10 14:41  plina  阅读(432)  评论(0编辑  收藏  举报