Exemplo n.º 1
0
 /// <summary>
 /// 验证
 /// </summary>
 /// <param name="target">验证目标</param>
 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 = Validator.TryValidateObject( target, context, validationResults, true );
     if ( !isValid )
         result.AddResults( validationResults );
     return result;
 }
Exemplo 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;
        }
Exemplo n.º 3
0
 public void TestAddResults_Null()
 {
     _results.AddResults(null);
     Assert.AreEqual(0, _results.Count);
 }