Surely you all have come across this: I have a property called LastName this is required. I do this:
ValidationRules.AddRule(CommonRules.StringRequired, "LastName");
The problem is user.BrokenRulesCollection[0].Description returns "LastName required". I can't display that to the user. I want to show "Last Name is required."
So, is CommonRules.StringRequired useless to me? Do I have to write a whole new custom validator just to display my custom message?
I can't believe anybody would really want to display "LastName required" to a user.
Chris
This topic has been discussed before. Do a search. Rocky may modify CSLA in the future to accomodate this scenario.
In the meantime I wrote code like this in my BO layer:
Public
Class MyRuleArgsThis allows me to use more constructors and to also pass in a value like "First Name" as the property description.
I actually have more code where I load a list of all field names and pull the corresponding description from the list so I do not have to code "First Name" at all in my BOs. But if I wanted to use a special value then whatever I pass in takes precedence over my list. e.g. "My Special First Name"
Joe
I'll almost certainly add a friendly name property to RuleArgs in the next version of the framework, yes. And that'll impact CommonRules of course, but also will make it easier to standardize on the same approach for custom rules.
I'm also strongly considering creating a DecoratedRuleArgs that uses the decorator pattern to minimize the need to create custom RuleArgs subclasses. Rather than having to create a custom object for each rule method, you'd be able to use DecoratedRuleArgs and just pass arbitrary name/value pairs into the rule.
The downside, of course, is loss of compile-time checking and type safety. But the upside is a much simpler and more standardized way of passing in arguments to rule methods.
In particular, this technique would simplify code generation rather a lot. Right now a would-be code generator has to somehow determine the type of args object required, and the properties that need to be set on that object. Quite challenging really, especially if you are creating a designer or anything for it. That's made simpler if arbitrary name/value pairs can be passed into the rule.
Copyright (c) Marimer LLC