Ejemplo n.º 1
0
        /// <summary>
        /// 处理验证错误
        /// </summary>
        /// <param name="results">
        /// 验证结果集合
        /// </param>
        public void Handle(ValidationResultCollection results)
        {
            if (results.IsValid)
            {
                return;
            }

            throw new Exception(results.First().ErrorMessage);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 验证
        /// </summary>
        /// <param name="target">
        /// 验证目标
        /// </param>
        /// <returns>
        /// The <see cref="ValidationResultCollection"/>.
        /// </returns>
        public ValidationResultCollection Validate(object target)
        {
            target.CheckNull("target");
            var result            = new ValidationResultCollection();
            var validationResults = new List <ValidationResult>();
            var context           = new ValidationContext(target, null, null);
            var isValid           = System.ComponentModel.DataAnnotations.Validator.TryValidateObject(target, context, validationResults, true);

            if (!isValid)
            {
                result.AddResults(validationResults);
            }

            return(result);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 处理错误
 /// </summary>
 /// <param name="results">
 /// 验证结果集合
 /// </param>
 public void Handle(ValidationResultCollection results)
 {
 }
Ejemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Validator2"/> class.
 /// 初始化验证操作
 /// </summary>
 public Validator2()
 {
     _result = new ValidationResultCollection();
 }