Exemple #1
0
        private static void FillFilterParameterAttributes(FilterSerializerData filterSerializerData, IFilter filter, Type filterType, FilterBindingContext context)
        {
            var propertyInfos = filterType.GetProperties().ToList();

            foreach (var propertyInfo in propertyInfos)
            {
                var filterParameterAttribute = AttributeRetrieval.GetAttribute <FilterParameterAttribute>(propertyInfo);
                if (filterParameterAttribute == null)
                {
                    continue;
                }

                //get the value set or bound to the parameter
                var value = GetFilterSerializationBindingValue(filterParameterAttribute, propertyInfo, context, filter);

                //run validation on the parameter to ensure that it meets all standards
                RunFilterSerializationValidation(filterType, propertyInfo, value);

                //run formatter on the validated value
                var filterPropertyFormattedValue = RunFilterSerializationFormat(filterParameterAttribute, filterType, propertyInfo, value);

                var filterPropertyIsDefault = filterParameterAttribute.Default != null &&
                                              value != null &&
                                              filterParameterAttribute.Default.Equals(value);

                filterSerializerData.Parameters.Add(new FilterSerializerDataParameter
                {
                    Name      = filterParameterAttribute.Name,
                    Value     = filterPropertyFormattedValue,
                    Parameter = filterParameterAttribute,
                    IsDefault = filterPropertyIsDefault
                });
            }
        }
        private static void FillFilterParameterAttributes(FilterSerializerData filterSerializerData, IFilter filter, Type filterType, FilterBindingContext context)
        {
            var propertyInfos = filterType.GetProperties().ToList();

            foreach (var propertyInfo in propertyInfos)
            {
                var filterParameterAttribute = AttributeRetrieval.GetAttribute<FilterParameterAttribute>(propertyInfo);
                if (filterParameterAttribute == null)
                {
                    continue;
                }

                //get the value set or bound to the parameter
                var value = GetFilterSerializationBindingValue(filterParameterAttribute, propertyInfo, context, filter);

                //run validation on the parameter to ensure that it meets all standards
                RunFilterSerializationValidation(filterType, propertyInfo, value);

                //run formatter on the validated value
                var filterPropertyFormattedValue = RunFilterSerializationFormat(filterParameterAttribute, filterType, propertyInfo, value);

                var filterPropertyIsDefault = filterParameterAttribute.Default != null
                                              && value != null
                                              && filterParameterAttribute.Default.Equals(value);

                filterSerializerData.Parameters.Add(new FilterSerializerDataParameter
                {
                    Name = filterParameterAttribute.Name,
                    Value = filterPropertyFormattedValue,
                    Parameter = filterParameterAttribute,
                    IsDefault = filterPropertyIsDefault
                });
            }
        }
        private static void FillFilterAttribute(FilterSerializerData filterSerializerData, IFilter filter, Type filterType)
        {
            var filterParameter = AttributeRetrieval.GetAttribute<FilterAttribute>(filterType);
            if (filterParameter == null)
            {
                throw new Exception(string.Format("IFilter type of \"{0}\", does not contain the FilterAttribute and must.", filterType.Name));
            }

            filterSerializerData.Filter = filterParameter;
        }
        public static FilterSerializerData GetFilterSerializerData(IFilter filter, FilterBindingContext context)
        {
            var filterType = filter.GetType();
            var filterSerializerData = new FilterSerializerData();

            FillFilterAttribute(filterSerializerData, filter, filterType);

            FillFilterParameterAttributes(filterSerializerData, filter, filterType, context);

            return filterSerializerData;
        }
Exemple #5
0
        private static void FillFilterAttribute(FilterSerializerData filterSerializerData, IFilter filter, Type filterType)
        {
            var filterParameter = AttributeRetrieval.GetAttribute <FilterAttribute>(filterType);

            if (filterParameter == null)
            {
                throw new Exception(string.Format("IFilter type of \"{0}\", does not contain the FilterAttribute and must.", filterType.Name));
            }

            filterSerializerData.Filter = filterParameter;
        }
Exemple #6
0
        public static FilterSerializerData GetFilterSerializerData(IFilter filter, FilterBindingContext context)
        {
            var filterType           = filter.GetType();
            var filterSerializerData = new FilterSerializerData();

            FillFilterAttribute(filterSerializerData, filter, filterType);

            FillFilterParameterAttributes(filterSerializerData, filter, filterType, context);

            return(filterSerializerData);
        }
Exemple #7
0
 public FilterSerializerWriter(FilterSerializerData filterData)
 {
     _filterData = filterData;
 }
 public FilterSerializerWriter(FilterSerializerData filterData)
 {
     _filterData = filterData;
 }