You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
764 B
32 lines
764 B
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace EC.Utils
|
|
{
|
|
/// <summary>
|
|
/// 排序
|
|
/// 版 本:V3.0.0
|
|
/// 版 权:EasyCode
|
|
/// 作 者:LXC
|
|
/// </summary>
|
|
public static partial class ExtLinq
|
|
{
|
|
public static IEnumerable<T> SortBy<T>(this IEnumerable<T> source, string propertyName, string sord)
|
|
{
|
|
var asc = true;
|
|
if (sord.ToUpper() == "DESC")
|
|
asc = false;
|
|
return SortBy(source, propertyName, asc);
|
|
}
|
|
|
|
public static IEnumerable<T> SortBy<T>(this IEnumerable<T> source, string propertyName, bool sord)
|
|
{
|
|
Func<T, object> func = s => s.GetType().GetProperty(propertyName).GetValue(s, null);
|
|
if (sord)
|
|
return source.OrderBy(func);
|
|
else
|
|
return source.OrderByDescending(func);
|
|
}
|
|
}
|
|
}
|