Example #1
0
        /// <summary>
        /// Validates <paramref name="target"/> using validation criteria specified for type <typeparamref name="T"/>
        /// through configuration for the default ruleset.
        /// </summary>
        /// <typeparam name="T">The type of object to validate.</typeparam>
        /// <param name="target">The instance of <typeparamref name="T"/> to validate.</param>
        /// <returns>A collection of with the results of the individual validations.</returns>
        public static ValidationResults ValidateFromConfiguration <T>(T target)
        {
            Validator <T> validator = ValidationFactory.CreateValidatorFromConfiguration <T>();

            return(validator.Validate(target));
        }
        private string GetValidationMessage(Validator validator)
        {
            if (validator == null)
                return "";

            var results = validator.Validate(this.target);
            if (results.IsValid)
                return "";

            var errorTextBuilder = new StringBuilder();
            foreach (var result in results)
            {
                errorTextBuilder.AppendLine(result.Message);
            }

            return errorTextBuilder.ToString();
        }
Example #3
0
        /// <summary>
        /// Validates <paramref name="target"/> using validation criteria specified for type <typeparamref name="T"/>
        /// through attributes on type <typeparamref name="T"/> and its ancestors for the default ruleset.
        /// </summary>
        /// <typeparam name="T">The type of object to validate.</typeparam>
        /// <param name="target">The instance of <typeparamref name="T"/> to validate.</param>
        /// <returns>A collection of with the results of the individual validations.</returns>
        public static ValidationResults ValidateFromAttributes <T>(T target)
        {
            Validator <T> validator = ValidationFactory.CreateValidatorFromAttributes <T>();

            return(validator.Validate(target));
        }