public static bool IsValid <T>(this IGridifyOrdering ordering, IGridifyMapper <T>?mapper = null) { if (string.IsNullOrWhiteSpace(ordering.OrderBy)) { return(true); } try { var orders = ParseOrderings(ordering.OrderBy !).ToList(); mapper ??= new GridifyMapper <T>(true); if (orders.Any(order => !mapper.HasMap(order.MemberName))) { return(false); } } catch (Exception) { return(false); } return(true); }
public static IEnumerable <Expression <Func <T, object> > > GetOrderingExpressions <T>(this IGridifyOrdering gridifyOrdering, IGridifyMapper <T>?mapper = null) { if (string.IsNullOrWhiteSpace(gridifyOrdering.OrderBy)) { throw new GridifyQueryException("OrderBy is not defined or not Found"); } var members = ParseOrderings(gridifyOrdering.OrderBy !).Select(q => q.MemberName).ToList(); if (mapper is null) { foreach (var member in members) { Expression <Func <T, object> >?exp = null; try { exp = GridifyMapper <T> .CreateExpression(member); } catch (Exception) { // skip if there is no mappings available } if (exp != null) { yield return(exp); } } } else { foreach (var member in members.Where(mapper.HasMap)) { yield return(mapper.GetExpression(member) !); } } }