How to validate this?

Topics: Validation Application Block
Apr 21, 2008 at 6:58 AM
I have no clue how to validate this:
Given is a simople class with 3 String Properties

public class ToValidate
public string Prop1{...}
public string Prop2{...}
public string Prop3{...}

If Prop1 has a specific value then Prop2 or Prop3 must also have (another) specific value. (It doesnt care if Prop2 AND Prop3 have this value...)
In other words: if Prop1' value is 'Value1' then must Prop2 or Prop3 have value 'Value2'.

Im using validation by configuration.Any hints how to validate. Thank you very much.

Apr 21, 2008 at 12:13 PM

I'm afraid you cannot express this kind of logic through configuration. The undelying validator object model would let you express it, but it would be hard for a user to interpret the resulting error messages.

Would defining a custom validator be a solution in your scenario?

Apr 21, 2008 at 12:49 PM
I thought about to use a custom validator. But I have problems to find some documentation about. A link would be helpful. But anyway thanks for your reply - it confirms my fear.

Apr 21, 2008 at 5:51 PM

maybe SelfValidation helps!?

Apr 22, 2008 at 6:59 AM
Edited Apr 22, 2008 at 7:55 AM
Yes, Self-Validation is a alternative.
But at first I try to avoid extra coding to have all validation actions at one point: configuration file.

If this is impossible I can decide to totaly hardcode this without VAB or to use SelfValidation. Although a Custom Validator must also be hardcoded (I think so, but as stated before I cannot find documentation) I can use the Custom Validator by configuration after its created by coding. Its a new (supporter-) class, but not a changed implementation of a businessclass. So I try to avoid a change in style.

Thanks for your hint.