Suggestion to add ValidationRules.RemoveRule

Suggestion to add ValidationRules.RemoveRule

Old forum URL: forums.lhotka.net/forums/t/2505.aspx


Vinodonly posted on Sunday, March 11, 2007

I have a requirement where rules on 3 business properties will only be applicable if a 4th business property is true.

I noticed that there is a AddRule method but there is no RemoveRule method in validation rules, pls correct me if I'm wrong.

This can be useful in this situation.

 

RockfordLhotka replied on Sunday, March 11, 2007

It should not be necessary. If your rules are sensitive to the state of the object, then the rules should include checks for that state.

In other words, what you are saying is that you have three rules that are "compound" rules: rules that have conditions dependent on multiple object properties. This is a rule implementation issue, not a reason to add/remove rules.

CSLA does a bunch of caching on rules after they've been added. If you read through the 2.1 Handbook, you'll see all the work that occurs early on to support short-circuting, per-type/per-instance rules, priorities and so forth.

If I open the door to add/remove over the life of the object, I'd need to trigger this processing each time. While I could do that, the performance impact would not be pretty...

You are far better off making your rule methods smarter.

Copyright (c) Marimer LLC