I found this method in other post, and I pretty much understand what's going on, except for the 4th line:
public static IQueryable<T> OrderByMember<T>(this IQueryable<T> source, string memberPath)
{
var expression = source.Expression;
var parameter = Expression.Parameter(source.ElementType, "x");
string[] paths = memberPath.Split('.');
/*****************HERE*******************/
var member = paths.Aggregate((Expression)parameter, Expression.PropertyOrField);
/****************************************/
var selector = Expression.Lambda(member, parameter);
var orderByCall = Expression.Call(typeof(Queryable), "OrderBy",
new Type[] { parameter.Type, member.Type },
expression, Expression.Quote(selector));
return source.Provider.CreateQuery<T>(orderByCall);
}
Why does IEnumerable<string>.Aggregate
accepts an Expression
and a MemberExpression
?
None of the overloads of Aggregate seem to match this call
Since I don't have a clue what's hapenning there, could you please explain?