Exemple #1
0
        /// <summary>
        /// Validates all properties.
        /// </summary>
        public void Validate()
        {
            // Validate each of the properties
            foreach (ValidatorList list in propertyCache.Values)
            {
                CheckValidProperty(list);
            }

            // If we have custom validation code, call it
            if (null != CustomValidation)
            {
                // Create an instance of CustomValidationEventArgs
                CustomValidationEventArgs e = new CustomValidationEventArgs();

                // Validate via the custom delegate
                CustomValidation(this, e);

                if (!e.IsValid)
                {
                    // Update validation messages
                    errorsDictionary["CustomValidation"] = new CustomValidatorAttribute(e.ErrorMessage, "", "");
                }
            }

        }
        /// <summary>
        /// Evaluates the is valid.
        /// </summary>
        /// <returns></returns>
        protected internal override bool EvaluateIsValid()
        {
            EventHandler<CustomValidationEventArgs> handler =
                Delegate.CreateDelegate(typeof (EventHandler<CustomValidationEventArgs>),
                                        PropertyToValidate.Target,
                                        ValidationMethod) as EventHandler<CustomValidationEventArgs>;

            CustomValidationEventArgs args = new CustomValidationEventArgs();
            handler(this, args);

            errMessage = args.ErrorMessage;
            return args.IsValid;
        }
		/// <inheritdoc />
        public override ValidationError BaseValidate(object targetObjectValue, object targetMemberValue, object context, InfoDescriptor infoDescriptor)
        {
            var args = new CustomValidationEventArgs(this, targetObjectValue, targetMemberValue, context);
            Handler(this, args);


            if (args.IsValid)
            {
                return null;
            }
            else
            {
                if (string.IsNullOrEmpty(args.ErrorMessage))
                {
                    return CreateValidationError(targetObjectValue, targetMemberValue, context, infoDescriptor);
                }
                else
                {
                    return new ValidationError(this, args.ErrorMessage, infoDescriptor, targetMemberValue);
                }
            }
        }