protected void MapFilterToViewData(TGetEntitiesQuery filter) { var properties = TypeInfoCache .GetPublicProperties(filter.GetType()) .Select(x => new { x.Name, Value = x.GetValue(filter) }) .Where(x => x.Value != null); foreach (var property in properties) { ViewData[property.Name] = property.Value; } }
private static string CalcOrderBy(Type type) { var orderByProps = TypeInfoCache.GetPublicProperties(type) .Select(x => new { Property = x, OrderByAttribute = x.GetCustomAttribute(typeof(OrderByAttribute)) as OrderByAttribute }) .Where(x => x.OrderByAttribute != null) .ToArray(); string orderBy = null; if (orderByProps.Length == 1) { orderBy = orderByProps[0].OrderByAttribute.IsDesc ? $"{orderByProps[0].Property.Name}.DESC" : orderByProps[0].Property.Name; } return(orderBy); }