/// <summary>
        /// When implemented in a derived class, returns metadata for client validation.
        /// </summary>
        /// <returns>
        /// The metadata for client validation.
        /// </returns>
        public override IEnumerable <ModelClientValidationRule> GetClientValidationRules()
        {
            IEntityValidationRule entityValidationRule = ValidationRule;
            string message = entityValidationRule.GetValidationMessage(Metadata.Model);
            ValidatorProperties validatorProperties = entityValidationRule.Validator.GetValidatorProperties();

            yield return
                (new ModelClientValidationStringLengthRule(
                     message,
                     validatorProperties.GetPropertyValue <int>(Constants.ValidationMessageParameterNames.MIN),
                     validatorProperties.GetPropertyValue <int>(Constants.ValidationMessageParameterNames.MAX)));
        }
        /// <summary>
        /// When implemented in a derived class, returns metadata for client validation.
        /// </summary>
        /// <returns>
        /// The metadata for client validation.
        /// </returns>
        public override IEnumerable <ModelClientValidationRule> GetClientValidationRules()
        {
            IEntityValidationRule entityValidationRule = ValidationRule;
            string message = entityValidationRule.GetValidationMessage(Metadata.Model);
            ValidatorProperties validatorProperties = entityValidationRule.Validator.GetValidatorProperties();

            yield return
                (new ModelClientValidationRangeRule(
                     message,
                     validatorProperties.GetPropertyValue(Constants.ValidationMessageParameterNames.FROM_VALUE),
                     validatorProperties.GetPropertyValue(Constants.ValidationMessageParameterNames.TO_VALUE)));
        }
Esempio n. 3
0
        /// <summary>
        /// When implemented in a derived class, returns metadata for client validation.
        /// </summary>
        /// <returns>
        /// The metadata for client validation.
        /// </returns>
        public override IEnumerable <ModelClientValidationRule> GetClientValidationRules()
        {
            IEntityValidationRule    entityValidationRule    = ValidationRule;
            IEntityPropertyValidator entityPropertyValidator = entityValidationRule.Validator;
            ValidatorProperties      validatorProperties     = entityPropertyValidator.GetValidatorProperties();
            string message = entityValidationRule.GetValidationMessage(Metadata.Model);

            yield return(new ModelClientValidationRegexRule(message, validatorProperties.GetPropertyValue <string>(Constants.ValidationMessageParameterNames.REGEX)));
        }
        /// <summary>
        /// When implemented in a derived class, returns metadata for client validation.
        /// </summary>
        /// <returns>
        /// The metadata for client validation.
        /// </returns>
        public override IEnumerable <ModelClientValidationRule> GetClientValidationRules()
        {
            ValidatorProperties validatorProperties       = ValidationRule.Validator.GetValidatorProperties();
            MemberInfo          memberToCompareMemberInfo = validatorProperties.GetPropertyValue <MemberInfo>(Constants.ValidationMessageParameterNames.MEMBER_TO_COMPARE_MEMBER_INFO);
            PropertyInfo        propertyInfoToCompare     = memberToCompareMemberInfo as PropertyInfo;

            if (propertyInfoToCompare != null)
            {
                string message   = ValidationRule.GetValidationMessage(Metadata.Model);
                Type   ownerType = validatorProperties.GetPropertyValue <Type>(Constants.ValidationMessageParameterNames.OWNER_TYPE);

                string validationModelPropertyName = propertyInfoToCompare.Name;
                string propertyName = GetTransformedPropertyName(validationModelPropertyName, ownerType) ?? validationModelPropertyName;

                string propertyForClientValidation = CompareAttribute.FormatPropertyForClientValidation(propertyName);
                yield return(new ModelClientValidationEqualToRule(message, propertyForClientValidation));
            }
        }