示例#1
0
        private SearchFilters GetFilters()
        {
            var filters = Filters?
                          .SelectMany(x => x.Filters);

            if (filters == null)
            {
                return(null);
            }

            var searchFilters = new SearchFilters();

            foreach (var filter in filters)
            {
                var property = searchFilters.GetType().GetProperty(filter.Type);
                if (property == null)
                {
                    continue;
                }

                var typeObject = property.GetValue(searchFilters);
                property = typeObject.GetType().GetProperty("Filters");
                if (property == null)
                {
                    continue;
                }

                var filtersObject = property.GetValue(typeObject);
                property = filtersObject.GetType().GetProperty(filter.Id);
                if (property == null)
                {
                    continue;
                }

                if (property.PropertyType == typeof(SearchFilterOption) && (filter.Enabled || filter.ApplyNegative))
                {
                    property.SetValue(filtersObject, new SearchFilterOption(filter.Enabled ? "true" : "false"));
                }
                else if (property.PropertyType == typeof(SearchFilterValue))
                {
                    if (!filter.Enabled)
                    {
                        continue;
                    }
                    var valueObject = new SearchFilterValue
                    {
                        Max    = filter.Max,
                        Min    = filter.Min,
                        Option = filter.Option?.Value,
                    };
                    property.SetValue(filtersObject, valueObject);
                }
            }

            searchFilters.TypeFilters.Filters.Category = new SearchFilterOption(SelectedCategory);

            return(searchFilters);
        }