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();
            }
        }
 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");
     }
 }
 private static bool TryValidate(object value, ValidationContext validationContext, ValidationAttribute attribute, out Validator.ValidationError validationError)
 {
     if (validationContext != null)
     {
         ValidationResult validationResult = attribute.GetValidationResult(value, validationContext);
         if (validationResult == ValidationResult.Success)
         {
             validationError = null;
             return(true);
         }
         validationError = new Validator.ValidationError(attribute, value, validationResult);
         return(false);
     }
     throw new ArgumentNullException("validationContext");
 }
 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");
 }