4

I search with reflector and I didn't manage to find a case where the ValidationResult.MemberNames is supposed to contain more than one value.

So, first of all I am wondering why MS had to do it IEnumerable<string>, then now that they already did this, can I rely that this property will only return one value?

Update
Concerning the DataAnnotations validation system I find more sloppiness:

  1. The TryValidateProperty and TryValidateObject should have removed the errors from the validationResults parameter if they don't exist any more.
  2. ValidationResult should have overriden Equals and GetHashCode.
  3. Why is the ValidationResult.ErrorMessage mutable!? I can't event build an EqualityComparer myself!
  4. If the DataTypeAttribute is only used for representation concerns, why does it inherit ValidationAttribute, that's just misleading, I had to struggle till I understood (after reflectoring) that its not going to work. MS just didn't implement it.

And the list goes on.

casperOne
  • 73,706
  • 19
  • 184
  • 253
Shimmy Weitzhandler
  • 101,809
  • 122
  • 424
  • 632
  • Indeed, the ValidationResult class is very ugly. And then the irony of its static readonly field named Success.. that's always null, so there's absolutely no chance of success. An instance of this nasty ValidationResult class is always a Failure. Not to mention that it's not serializable.. – ducu Jan 24 '13 at 14:06

1 Answers1

4

Consider Password and PasswordConfirmation. Or any Start/Stop values, or any other cross-field validation.

Jeff Handley
  • 4,134
  • 2
  • 23
  • 23