示例#1
0
        /// <summary>
        /// Validates the specified instance.
        /// </summary>
        /// <param name="context">Validation Context</param>
        /// <returns>A ValidationResult object containing any validation failures.</returns>
        public virtual ValidationResult Validate(ValidationContext <T> context)
        {
            context.Guard("Cannot pass null to Validate");
            var failures = nestedValidators.SelectMany(x => x.Validate(context)).ToList();

            return(new ValidationResult(failures));
        }
        /// <summary>
        /// Validates the specified instance.
        /// </summary>
        /// <param name="context">Validation Context</param>
        /// <returns>A ValidationResult object containing any validation failures.</returns>
        public virtual ValidationResult Validate(ValidationContext <T> context)
        {
            context.Guard("Cannot pass null to Validate.");
            EnsureInstanceNotNull(context.InstanceToValidate);
            var failures = nestedValidators.SelectMany(x => x.Validate(context));

            return(new ValidationResult(failures));
        }
        private List <ValidationError> Validate(
            T objectToValidate,
            IValidatorSelector validatorSelector)
        {
            objectToValidate.NotNull(nameof(objectToValidate));

            var context = new ValidationContext <T>(objectToValidate, validatorSelector);

            return(_nestedValidators.SelectMany(x => x.Validate(context)).ToList());
        }
        /// <summary>
        /// Validates the specified instance.
        /// </summary>
        /// <param name="context">Validation Context</param>
        /// <returns>A ValidationResult object containing any validation failures.</returns>
        public virtual ValidationResult Validate(ValidationContext <T> context)
        {
            context.Guard("Cannot pass null to Validate.");
            context.InstanceToValidate.Guard("Cannot a pass null model to Validate.");
            var failures = nestedValidators.SelectMany(x => x.Validate(context)).ToList();

            if (Request == null)
            {
                Request = context.Request;
            }

            return(new ValidationResult(failures)
            {
                Request = Request
            });
        }