Validation Context

Topics: Developer Forum
Apr 13, 2007 at 2:30 PM
Edited Apr 13, 2007 at 2:31 PM

We have spoken before about this, I have a Entity Document containing Entities and as mentioned previously I cannot easily navigate round that tree, i.e. go backwards up the tree and that's unlikely to change:(

What would be useful if that I could pass in some sort of validation context when calling Validate that would be available when executing a rule, in my case that context would be the Entity Document. I'm guessing that sort of thing would need to come in via CustomValidationEventArgs?

In my context it is an Entity Document but I guess it could equally be an object detailing logged on user priviliges or anything that may affect the validation logic.

This sort of thing possible, feasible, desirable?


- Andrew
Apr 15, 2007 at 7:56 AM
Morning Simon,

Just wondered if you have any thoughts on the above?


- Andrew
Apr 15, 2007 at 9:10 AM
I have.
I just checked in some code that changes the Rule.Validate to accept a context object. ParameterValidationManager, PropertyValidationManager and the various base classes have been given overloaded methods and constructors to support this feature.

Is this what you had in mind?

No doco or unit tests yet. They will come in the next checkin. I just wanted confirmation that it met your requirements first.

Apr 15, 2007 at 6:23 PM
Very much so! I will download now, should be able to have a play Monday morning...


- Andrew
Apr 16, 2007 at 7:47 AM
Morning Simon,

Had a play with this last night...had difficulty in working out to access the context from rule.

Expected to see code like...

public CustomValidationEventArgs(object targetObjectValue, object targetMemberValue,object context)

And then picking up the context from there inside the rule.

I did modify code to achieve that for Custom Rules and it seemed to work OK.

Am I barking up the wrong tree? Is that not the way you intended this change to work?


- Andrew
Apr 16, 2007 at 8:05 AM
Edited Apr 16, 2007 at 8:06 AM
Evening Andrew
I actually thought about today. Yes you are correct, I forgot that scenario.
I have checked in the code to rectify the situation.
And yes, your code is correct.
Apr 16, 2007 at 8:55 AM
Thanks Simon!

Also noticed that there wasn't (I think!) a Validate call with just Property and Context, any reason for this?

- Andrew
Apr 22, 2007 at 3:46 AM
As you have probably already worked out there the context is passed in on the constructor of the PropertyValidationManager and hence is not required on each validate method.