static IEnumerable <TItem> Order <TItem>(IEnumerable <TItem> queryable, Func <Type, string, object> getArguments) { var items = queryable.ToList(); var orderBys = ArgumentReader.ReadOrderBy(getArguments).ToList(); IOrderedEnumerable <TItem> ordered; if (orderBys.Count > 0) { var orderBy = orderBys.First(); var property = FuncBuilder <TItem> .BuildPropertyExpression(orderBy.Path); if (orderBy.Descending) { ordered = items.OrderByDescending(property); } else { ordered = items.OrderBy(property); } } else { return(items); } foreach (var orderBy in orderBys.Skip(1)) { var property = FuncBuilder <TItem> .BuildPropertyExpression(orderBy.Path); if (orderBy.Descending) { ordered = ordered.ThenByDescending(property); } else { ordered = ordered.ThenBy(property); } } return(ordered); }
static IQueryable <TItem> Order <TItem>(IQueryable <TItem> queryable, Func <Type, string, object> getArguments) { var orderBys = ArgumentReader.ReadOrderBy(getArguments).ToList(); IOrderedQueryable <TItem> ordered; if (orderBys.Count > 0) { var orderBy = orderBys.First(); var property = PropertyCache <TItem> .GetProperty(orderBy.Path).Lambda; if (orderBy.Descending) { ordered = queryable.OrderByDescending(property); } else { ordered = queryable.OrderBy(property); } } else { return(queryable); } foreach (var orderBy in orderBys.Skip(1)) { var property = PropertyCache <TItem> .GetProperty(orderBy.Path).Lambda; if (orderBy.Descending) { ordered = ordered.ThenByDescending(property); } else { ordered = ordered.ThenBy(property); } } return(ordered); }