public ISortableFilter <T> ApplySortable <T>(ISortableFilter <T> filter, string propertyName = null, SortDirection sortDirection = SortDirection.Ascending) { ApplySortable(filter, propertyName); filter.SortDirection = sortDirection; return(filter); }
public ISortableFilter <T> ApplySortable <T>(ISortableFilter <T> filter, string propertyName = null, string sortDirection = nameof(SortDirection.Ascending)) { ApplySortable(filter, propertyName); if (Enum.TryParse(sortDirection, out SortDirection sd)) { filter.SortDirection = sd; } return(filter); }
private void ApplySortable <T>(ISortableFilter <T> filter, string propertyName = null) { if (!string.IsNullOrWhiteSpace(propertyName)) { var property = typeof(T) .GetProperties() .FirstOrDefault(x => x.Name == propertyName); if (property != null) { var parameterExpression = Expression.Parameter(typeof(T)); var propertyExpression = Expression.Property(parameterExpression, property); var convertedPropertyExpression = Expression.Convert(propertyExpression, typeof(object)); var propertyFunction = Expression.Lambda <Func <T, object> >(convertedPropertyExpression, parameterExpression).Compile(); filter.Sort = propertyFunction; } } }