Permalink
Browse files

Update data annotations validation to include class level attributes

  • Loading branch information...
1 parent b4e3bb3 commit 9f207dd32e6d6955743d9fc16e7e6b0de2c929b4 @xt0rted xt0rted committed Mar 2, 2014
@@ -142,7 +142,7 @@ private class OopsValidationAttribute : ValidationAttribute
{
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
- return new ValidationResult("Oops");
+ return new ValidationResult("Oops", new[] { string.Empty });
}
}
@@ -38,7 +38,7 @@ protected DataAnnotationsValidatorAdapter(string ruleType)
/// <returns>An <see cref="IEnumerable{T}"/> of <see cref="ModelValidationRule"/> instances.</returns>
public virtual IEnumerable<ModelValidationRule> GetRules(ValidationAttribute attribute, PropertyDescriptor descriptor)
{
- yield return new ModelValidationRule(ruleType, attribute.FormatErrorMessage, descriptor == null ? null : new[] { descriptor.Name });
+ yield return new ModelValidationRule(ruleType, attribute.FormatErrorMessage, new [] { descriptor == null ? string.Empty : descriptor.Name });
}
/// <summary>
@@ -38,6 +38,17 @@ public IEnumerable<IPropertyValidator> GetValidators(Type type)
var results =
new List<IPropertyValidator>();
+ var classAttributes =
+ typeDescriptor.GetAttributes().OfType<ValidationAttribute>();
+
+ var classValidator =
+ new PropertyValidator
+ {
+ AttributeAdaptors = this.GetAttributeAdaptors(classAttributes)
+ };
+
+ results.Add(classValidator);
+
foreach (PropertyDescriptor descriptor in propertyDescriptors)
{
var attributes =

0 comments on commit 9f207dd

Please sign in to comment.