///& lt; Summary>
///according to the specified attribute name
sorting sequence///& lt;/summary>
///& lt; Typeparam name="T" & gt; The type of the elements in the source & lt;/typeparam>
///& lt; Param name="source" & gt; To sort the values of the sequence & lt;/param>
///& lt; Param name="property" & gt; The attribute name & lt;/param>
///& lt; Param name="item first-just & gt;" Whether descending & lt;/param>
///& lt; Returns>
Public static IEnumerableOrderBy (this IEnumerable The source, the string property, bool item first-just) where T: class
{
ParameterExpression param=Expression. The Parameter (typeof (T), "c");
PropertyInfo PI=typeof (T). GetProperty (property);
MemberExpression selector=Expression. MakeMemberAccess (param, PI);
LambdaExpression le=Expression. Lambda (selector, param);
String methodName=(item first-just)? "OrderByDescending" : the "OrderBy";
MethodCallExpression resultExp=Expression. The Call (typeof (Queryable), methodName, new Type [] {typeof (T), PI, PropertyType}, source, Expression, le);
Return to the source. The Provider. CreateQuery(resultExp);
}
CodePudding user response:
IEnumerable?????????????????????????
Since to do expression, please use the IQueryable