private static void FillSettingParameterAttributes(SettingSerializerData settingSerializerData, ISetting setting, Type settingType) { var propertyInfos = settingType.GetProperties().ToList(); foreach (var propertyInfo in propertyInfos) { var settingParameterAttribute = AttributeRetrieval.GetAttribute <SettingParameterAttribute>(propertyInfo); if (settingParameterAttribute == null) { continue; } var settingPropertyValue = propertyInfo.GetValue(setting); RunSettingSerializationValidation(settingType, propertyInfo, settingPropertyValue); var settingPropertyFormattedValue = RunSettingSerializationFormat(settingParameterAttribute, settingType, propertyInfo, settingPropertyValue); settingSerializerData.Parameters.Add(new SettingSerializerDataParameter { Value = settingPropertyFormattedValue, Parameter = settingParameterAttribute, }); } }
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 SettingAttribute GetSettingsAttribute(ISetting setting) { var settingsAttribute = AttributeRetrieval.GetAttribute <SettingAttribute>(setting.GetType()); if (settingsAttribute == null) { throw new InvalidOperationException(string.Format("ISetting \"{0}\", does not include the SettingAttribute.", setting.GetType().Name)); } return(settingsAttribute); }
private static void FillSettingAttribute(SettingSerializerData settingSerializerData, ISetting setting, Type settingType) { var settingParameter = AttributeRetrieval.GetAttribute <SettingAttribute>(settingType); if (settingParameter == null) { throw new Exception(string.Format("ISetting type of \"{0}\", does not contain the FilterAttribute and must.", settingParameter.Name)); } settingSerializerData.Setting = settingParameter; }
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 string EnumDefaultValue <TValue>(TValue enumValue, bool convertIdentifiers = false) { var enumType = enumValue.GetType(); var enumMember = enumType.GetMember(enumValue.ToString()); var enumAttribute = AttributeRetrieval.GetAttribute <SerializedAsAttribute>(enumMember.First()); if (enumAttribute != null) { return(enumAttribute.Name); } return(EnumValue(enumValue, convertIdentifiers)); }
public static int GetFilterInputMax(Filterchain filterchain) { if (filterchain == null) { throw new ArgumentNullException("filterchain"); } return(filterchain.Filters.Min(f => { var filterAttribute = AttributeRetrieval.GetAttribute <FilterAttribute>(f.GetType()); return filterAttribute.MaxInputs; })); }