Exemplo n.º 1
0
        protected override void Initialize(ContentCompiler compiler)
        {
            _compiler = compiler;
            var type = ReflectionHelpers.GetBaseType(TargetType);

            if (type != null && type != typeof(object) && !TargetType.IsValueType)
            {
                _baseType = type;
            }

            var runtimeType = TargetType.GetCustomAttributes(typeof(ContentSerializerRuntimeTypeAttribute), false).FirstOrDefault() as ContentSerializerRuntimeTypeAttribute;

            if (runtimeType != null)
            {
                _runtimeType = runtimeType.RuntimeType;
            }

            var typeVersion = TargetType.GetCustomAttributes(typeof(ContentSerializerTypeVersionAttribute), false).FirstOrDefault() as ContentSerializerTypeVersionAttribute;

            if (typeVersion != null)
            {
                _typeVersion = typeVersion.TypeVersion;
            }

            _properties = TargetType.GetAllProperties().Where(IsValidProperty).ToArray();
            _fields     = TargetType.GetAllFields().Where(IsValidField).ToArray();
        }
Exemplo n.º 2
0
        private void LoadValidators()
        {
            var props = TargetType.GetProperties();

            PropertyDescriptors = props.Select(prop => new PropertyDescriptor(prop)).ToDictionary(p => p.Property.Name);

            ErrorValidators = props.ToDictionary(key =>
                                                 new PropertyDescriptor(key),
                                                 value =>
            {
                return(value.GetCustomAttributes <ValidationAttribute>(true)
                       .Where(a => !(a is WarningValidationAttribute)).ToList());
            }
                                                 );
            WarningValidators = props.ToDictionary(key => new PropertyDescriptor(key),
                                                   value =>
            {
                return(value.GetCustomAttributes <ValidationAttribute>(true)
                       .Where(a => (a is WarningValidationAttribute)).ToList());
            }
                                                   );
            ClassValidators = TargetType.GetCustomAttributes <ValidationAttribute>(false).ToList();
        }