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); } }