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,
                });
            }
        }
Exemplo n.º 2
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
                });
            }
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        public static bool Validate(ISetting setting)
        {
            var settingType       = setting.GetType();
            var settingParameters =
                settingType.GetProperties()
                .Where(p => AttributeRetrieval.GetAttributes <ValidateAttribute>(p).Any())
                .Select(p => new { Info = p, Value = p.GetValue(setting) })
                .ToList();

            return(settingParameters.All(p => Validate(settingType, p.Info, p.Value)));
        }
Exemplo n.º 5
0
        public static bool Validate(IFilter filter)
        {
            var filterType       = filter.GetType();
            var filterParameters =
                filterType.GetProperties()
                .Where(p => AttributeRetrieval.GetAttributes <ValidateAttribute>(p).Any())
                .Select(p => new { Info = p, Value = p.GetValue(filter) })
                .ToList();

            return(filterParameters.All(p => Validate(filterType, p.Info, p.Value)));
        }
        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;
        }
Exemplo n.º 7
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;
        }
Exemplo n.º 8
0
        /// <summary>
        /// returns a boolean indicating if <cref name="objectType"/> is applicable to <cref name="restrictedType"/>
        /// </summary>
        public static bool ContainsStream(Type objectType, Type streamType)
        {
            var matchingAttributes = AttributeRetrieval.GetAttributes <ContainsStreamAttribute>(objectType);

            if (matchingAttributes.Count == 0)
            {
                return(false);
            }

            return(matchingAttributes.Any(attribute => (attribute.Type == streamType ||
                                                        attribute.Type.IsAssignableFrom(streamType))));
        }
Exemplo n.º 9
0
        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));
        }
Exemplo n.º 10
0
        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;
            }));
        }
Exemplo n.º 11
0
        public static bool Validate(Type objectType, PropertyInfo propertyInfo, object value)
        {
            var validateAttributes = AttributeRetrieval.GetAttributes <ValidateAttribute>(propertyInfo);

            return(validateAttributes == null || !validateAttributes.Any() || validateAttributes.All(va => ValidateSingle(propertyInfo, va, value)));
        }