I use split classes and Codegen as much of my Base class as possible. Whenever I have a Status field I add a rule like this: (for Active and De-active values.)
ValidationRules.AddRule(AddressOf ContainsValidValue, New ValidValuesRuleArgs("Status", "A", "D"))
But in a recnet case, it turns out that both A and D are not part of the list of status values.
so in my developer level class I would like to call
Protected Overrides Sub AddBusinessRules() 'Here is where I want to remove the rule above and add a new one below.
'But I do not see a ValidationRules.RemoveRule method.
'Status
ValidationRules.AddRule(AddressOf StatusContainsValidValue, New PNIRuleArgs("Status"))
I do not see a way to remove the rule.
Any tips?
Rocky - does it make sense to have such a method?
Short term - I can always codegen things differently. But I would like a longer term solution.
Joe
I suppose it would be possible to remove a rule - though you'd need to know its full name. In 2.1 now, that is possible, because of the new rule://method/property?arg1=val1 scheme for naming rules. That URI is the rule's unique name, and would allow removal of a specific rule.
I'm not sure that would help you necessarily though, as you'd have to be able to create that full URI to identify the specific rule to be removed. Unless I supported a wildcard scheme by which you could remove rule://method/property?* or something like that.
Andres,
I am using Type rules. The real problem is that I codegen the rule for Status (and assumed that A and D would be in the list of valid values) and now I have to either:
1. Comment out the rule in my Gen level class (which will work for now but if the class is ever re-generated then it is posisble that the rule would not be commented out in the future.)
2. Remove the rule in my developer level class and add a new rule for the Status field which uses the correct values.
So I do not need Instance rules - the rule I Generated is "bad code" and now I need to remove it for the Type and add back a new rule.
As I said, modifying the code gen process to not create the rule in the first place is a better idea - but I am looking for a different solution right now. I want to be able to use RemoveRule as easily as AddRule.
Thanks.
Joe
Yes - I do have Codesmith templates which I may have to alter.
But, that is not the point of the question.
I would appreciate suggestions/comments about the the need/ability to remove rules if applied in a codegen class and you need/want to assign a different rule in the developer level class.
Assuming the need to do so is valid - what is required in the framework to create a method called RemoveRule? What would it have to know and be able to do?
Thanks.
Joe
I like the idea of being able to Override a separate function. The default behavior of the function would be to call the Shared rule. But if I Override it then I can write anything I need.
Thanks - I will try to implement it.
I tried it out for the Rule but since Shared methods are not Overridable it did not work. Then I moved everything to Instance Rules which are not Shared and I could override it. But I didn't like that.
So I left the original rule in place but coded an overridable function to get the list of valid values.
That works nicely and I will add that to my template. Thanks for the idea.
ValidationRules.AddRule(
AddressOf ContainsValidValue, New ValidValuesRuleArgs("Status", GetValidValues))etc.
Public Overridable Function GetValidValues() As String()In the Developer level class I use:
Public Overrides Function GetValidValues() As String()Joe
Copyright (c) Marimer LLC