Beispiel #1
0
        public static void ValidateArray(object[] items, GeneralControlMetadata itemMetadata)
        {
            Type validatorType = ControlValidatorCache.GetValidator(itemMetadata.GetType());
            IControlValidator itemValidator = (IControlValidator)Activator.CreateInstance(validatorType);

            for (int i = 0; i < items.Length; i++)
            {
                itemValidator.Validate(items[i], itemMetadata);
            }
        }
Beispiel #2
0
        public static void Validate(object model, IControlGroup metadata)
        {
            Tuple <string, GeneralControlMetadata>[] controls = metadata.controls.Select(x => Tuple.Create(x.Key, x.Value)).ToArray();

            Type modelType = model.GetType();

            foreach (var control in controls)
            {
                Type controlMetadataType           = control.Item2.GetType();
                Type validatorType                 = ControlValidatorCache.GetValidator(controlMetadataType);
                IControlValidator controlValidator = (IControlValidator)Activator.CreateInstance(validatorType);

                object value = modelType.GetProperty(control.Item1).GetValue(model, null);
                GeneralControlMetadata controlMetadata = control.Item2;

                controlValidator.Validate(value, controlMetadata);
            }
        }