TryValidate

Topics: Developer Forum
Apr 16, 2007 at 4:02 PM
Simon,

Does TryValidate need to have a RuleSet parameter?

Need to avoid an exception if property is not found but need to do this in conjunction with a Rule Set.

Thanks,

- Andrew
Apr 17, 2007 at 1:19 AM
Andrew

PropertyValidationManager maintains the state of it validity. That is, when properties are validated, it remembers the state so that the next time IsValid is called all properties do not need to be validated again. Because of this RuleSet is passed in on the constructor and all Validate, and TryValidate, methods will use that RuleSet.

So to validate on multiple different RuleSets you will need multiple PropertyValidationManagers. PropertyValidationManager is a class (memory wise) so this should be an acceptable scenario.

I have actually been thinking of implementing some static methods on PropertyValidationManager that just validate individual properties and ignore state. Does this map closes to your use of the API?
Apr 17, 2007 at 9:07 AM
Morning Simon,

I think it was a case of me being a bit daft:(

As things stand at the moment TryValidate is more than adequate.

Might be useful to validate individual properties and ignore state though...generally the concept of effectively forcing a re-evaluate would be useful I think.

Regards,

- Andrew
Apr 22, 2007 at 4:50 AM
Andrew
I have added a number of static (and hence stateless) Validate and TryValidate methods to the PropertyValidationManager. They all return an IList of ValidationResults. The IList will be empty if there are no Rules that fail.