private static object GetFilterSerializationBindingValue(FilterParameterAttribute filterParameterAttribute, PropertyInfo propertyInfo, FilterBindingContext context, IFilter filter) { if (filterParameterAttribute.Binding == null) { return(propertyInfo.GetValue(filter)); } var bindingObject = (IFilterParameterBinding)Activator.CreateInstance(filterParameterAttribute.Binding); return(bindingObject.GetValue(context)); }
private static string RunFilterSerializationFormat(FilterParameterAttribute filterParameterAttribute, Type filterType, PropertyInfo propertyInfo, object value) { if (value == null) { return(string.Empty); } if (filterParameterAttribute.Formatter == null) { decimal decValue; return(Decimal.TryParse(value.ToString(), out decValue) ? decValue.ToString(CultureInfo.InvariantCulture) : value.ToString()); } if (!typeof(IFormatter).IsAssignableFrom(filterParameterAttribute.Formatter)) { throw new Exception(string.Format("IFilter type of \"{0}\" parameter \"{1}\", Formatter must be of type IFilterParameterFormatter.", filterType.Name, propertyInfo.Name)); } var formatterFromAttribute = (IFormatter)Activator.CreateInstance(filterParameterAttribute.Formatter); return(formatterFromAttribute.Format(value)); }