Exemplo n.º 1
0
        public static TypeFilter FilterConverter(PropertiesFilter filters)
        {
            var result = new TypeFilter(new Dictionary <string, TypeFilter>(filters.Count));

            foreach (var filter in filters.Values.Where(f => f.Value != null))
            {
                switch (filter.Value)
                {
                case PropertiesFilter innerFilter:
                    result.PropertyFilters.Add(filter.Key.Name, FilterConverter(innerFilter));
                    break;

                case Delegate predecate:
                    result.PropertyFilters.Add(filter.Key.Name, new TypeFilter(predecate));
                    break;

                default:
                    if (filter.SourceList != null)
                    {
                        result.PropertyFilters.Add(filter.Key.Name, new TypeFilter(CreateStringFilter(filter.Value.ToString(), filter.SourceList)));
                    }
                    else
                    {
                        result.PropertyFilters.Add(filter.Key.Name, new TypeFilter(CreateStringFilter(filter.Value.ToString())));
                    }
                    break;
                }
            }
            return(result.PropertyFilters.Count > 0 ? result : null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create predicate from filter's data
        /// </summary>
        /// <typeparam name="T">Type of filtered source</typeparam>
        /// <param name="filter">|Filter's data</param>
        /// <returns>Filter's predicate</returns>
        public static Func <T, bool> CreateFilter <T>(PropertiesFilter filter)
        {
            var propertyFilters = FilterConverter(filter);

            if (propertyFilters == null)
            {
                return(null);
            }
            var validator = PropertiesFilter.CreateFilter <T>(propertyFilters);

            return(validator);
        }