Exemplo n.º 1
0
        /// <summary>
        /// Performs validation on the decorated class member and returns the validation result.
        /// </summary>
        /// <returns></returns>
        protected override ValidationResult IsValid(object value, ValidationContext validationContext)
        {
            validationContext.CheckNotNull(nameof(validationContext));
            var results = new List <ValidationResult>();
            var context = new ValidationContext(value, null, null);

            Validator.TryValidateObject(value, context, results, true);

            if (results.Count != 0)
            {
                var compositeResults = new CompositeValidationResult("Validation for {0} failed!".FormatInvariant(validationContext.DisplayName));
                results.ForEach(compositeResults.AddResult);

                return(compositeResults);
            }

            return(ValidationResult.Success);
        }