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