public Func <IEnumerable <T>, IEnumerable <T> > CreateFunction <T>() { ParameterExpression param = Expression.Parameter(typeof(IEnumerable <T>), "arg"); IEnumerable <OrderByItem> items = OrderByItems; // this does a recursive search - cache it since we are using it twice OrderByItem first = items.First(); Debug.Assert(first != null); MethodCallExpression call = first.CreateExpression(param, typeof(T)); foreach (OrderByItem orderby in items.Except(new OrderByItem[] { first })) { call = orderby.CreateThenByExpression(call, typeof(T)); } return(Expression.Lambda <Func <IEnumerable <T>, IEnumerable <T> > >(call, param).Compile()); }
public Func <IEnumerable <T>, IEnumerable <T> > CreateEvaluator <T>() { ParameterExpression param = Expression.Parameter(typeof(IEnumerable <T>), "arg"); IEnumerable <OrderByItem> items = OrderByItems; // this does a recursive search - cache it since we are using it twice OrderByItem first = items.First(); Debug.Assert(first != null); // since ordering after the first uses the ThenBy* methods first create the OrderBy call // and then all of the subsequent ThenBy valls MethodCallExpression call = first.CreateExpression(param, typeof(T)); foreach (OrderByItem orderby in items.Skip(1)) // skip the first one because that was used above { call = orderby.CreateThenByExpression(call, typeof(T)); } return(Expression.Lambda <Func <IEnumerable <T>, IEnumerable <T> > >(call, param).Compile()); }