Different composition for attribute validation

Topics: Validation Application Block
Mar 12, 2007 at 10:14 PM
Is there a way to have two types of validator composition when using attributes? For example, a field must meet validator A and either validator B or validator C?

I see using ValidatorComposition you can change the composition type, but it seems that is a global change (i.e. validator A OR validator B OR validator C vs validator A AND validator B AND validator C)

Is there a way to use attributes to define the condition
validator A AND (validator B OR validator C)

Mar 12, 2007 at 10:49 PM
In general you can't do this from attributes - unfortunately the attribute syntax made it difficult to express complex relationships like this.

However we did do some extra work to make it possible to OR a null check with a bunch of other ANDed validators using the IgnoreNullsAttribute. Thus:
is equivalient to NotNullValidator(Negated=true) OR (ValidatorA AND ValidatorB).

If you want anything more complex, you'll need to use configuration or encapsulate the desired Boolean logic into your own attributes.

Mar 12, 2007 at 11:06 PM

In general the IgnoreNulls with the others - does handle most of the average cases, and it would seem that for more complex scenarios I would assume you could use rulesets to divide up rules, then a self validation function to fire those rules, checking the rulesets as needed to form the complex logic.

Thanks for the response.