예제 #1
0
        public static ValidatorRules ValidatorRules(this ElementRequest elementRequest)
        {
            var command = elementRequest.FindModel();

            var validator = (IValidator)elementRequest.Get(typeof(IValidator <>).MakeGenericType(command.GetType()));

            if (validator == null)
            {
                return(new ValidatorRules(new List <IPropertyValidator>()));
            }

            string propertyFullName = elementRequest.FindPropertyFullName();

            var builder = validator.RulesFor(propertyFullName);

            if (builder.Has <IPropertyValidator>())
            {
                return(builder);
            }

            // the property's owner type has a specialized validator
            validator = (IValidator)elementRequest.Get(typeof(IValidator <>).MakeGenericType(elementRequest.HolderType()));

            if (validator == null)
            {
                return(new ValidatorRules(new List <IPropertyValidator>()));
            }

            var propertyName = elementRequest.Accessor.Name;

            return(validator.RulesFor(propertyName));
        }
예제 #2
0
 public bool Matches(ElementRequest elementRequest) =>
 elementRequest.FindModel().GetType().Implements <INoEditorEnricher>() == false;