예제 #1
0
        public static void ValidateProperty(object value, ValidationContext validationContext)
        {
            Type propertyType = Validator.s_store.GetPropertyType(validationContext);

            Validator.EnsureValidPropertyType(validationContext.MemberName, propertyType, value);
            IEnumerable <ValidationAttribute> propertyValidationAttributes = Validator.s_store.GetPropertyValidationAttributes(validationContext);

            Validator.ValidationError validationError = Validator.GetValidationErrors(value, validationContext, propertyValidationAttributes, false).FirstOrDefault();
            if (validationError != null)
            {
                validationError.ThrowValidationException();
            }
        }
예제 #2
0
 public static void ValidateValue(object value, ValidationContext validationContext, IEnumerable <ValidationAttribute> validationAttributes)
 {
     if (validationContext != null)
     {
         Validator.ValidationError validationError = Validator.GetValidationErrors(value, validationContext, validationAttributes, false).FirstOrDefault();
         if (validationError != null)
         {
             validationError.ThrowValidationException();
         }
     }
     else
     {
         throw new ArgumentNullException("validationContext");
     }
 }
예제 #3
0
 public static void ValidateObject(object instance, ValidationContext validationContext, bool validateAllProperties)
 {
     if (instance != null)
     {
         if (validationContext != null)
         {
             if (instance == validationContext.ObjectInstance)
             {
                 Validator.ValidationError validationError = Validator.GetObjectValidationErrors(instance, validationContext, validateAllProperties, false).FirstOrDefault();
                 if (validationError != null)
                 {
                     validationError.ThrowValidationException();
                 }
                 return;
             }
             throw new ArgumentException(@"Instance Must Match Validation Context Instance.", "instance");
         }
         throw new ArgumentNullException("validationContext");
     }
     throw new ArgumentNullException("instance");
 }