linq动态分页排序

if (!string.IsNullOrEmpty(order) && !string.IsNullOrEmpty(dir))//判断排序的字段名称和排序的类型是否为空
{
if (dir.Equals("asc"))
{
list1 = listData.OrderBy(p => GetPropertyValue(p, order)).Skip(start).Take(limit).ToList();
}
else
{
list1 = listData.OrderByDescending(p => GetPropertyValue(p, order)).Skip(start).Take(limit).ToList();
}
}

 

 

private static object GetPropertyValue(object obj, string property)
{
System.Reflection.PropertyInfo propertyInfo = obj.GetType().GetProperty(property);
return propertyInfo.GetValue(obj, null);
}

posted @ 2017-07-06 14:09  凤山朱德  阅读(403)  评论(0编辑  收藏  举报