Rocky: Need RuleArgs.ToString() Standard for multiple arguments

Rocky: Need RuleArgs.ToString() Standard for multiple arguments

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


david.wendelken posted on Thursday, November 09, 2006

Version 2.1

I'm working with adding a public list of rule descriptions suitable for end-users in my own subclasses of BusinessBase, ReadOnlyBase, etc.   When done, I'm going to add them to CSLA Contrib.

As the input for the user rule descriptions I'm using the ValidationRules.GetRuleDescriptions() routine.

As a reminder, the output for each rule is like this:

_ruleName = "rule://" + _handler.Method.Name + "/" + _args.ToString();

_args is a RuleArgs class.

The sample RuleArgs-based class's ToString() method outputs in this style:

propertyname + "?parameterName=" + parameterValue.ToString();

So, here's my Question:

If a custom RuleArgs class has more than one parameter value, what delimiter is everyone supposede to use between parameter name/value pairs?

I'm guessing one of two options:

? or &

The latter choice would be similar to the way URL parameters are passed, where the first one is denoted by a ? and the rest start with &.

What's your choice?

Thanks!

 

 

 

 

RockfordLhotka replied on Thursday, November 09, 2006

You should use &.

The reason I went with this URI style format is because you can use System.Uri to parse the text. For this to work, the combined ToString() value must return a properly formatted URI.

JoeFallon1 replied on Friday, November 10, 2006

Good question.

Thanks for the response.

Fixed a couple of small bugs with that one.

Joe

 

david.wendelken replied on Friday, November 10, 2006

RockfordLhotka:
You should use &.

The reason I went with this URI style format is because you can use System.Uri to parse the text. For this to work, the combined ToString() value must return a properly formatted URI.

Thanks for the response!

I tried out System.Uri but it has unpleasant side effects.  It turns some of the information into all lowercase strings.  It would make my parsing easier but maintenance of the resource files that contain the rule messages harder to maintain.  (ruleIntegerMaxValue would become ruleintegermaxvalue, which is a distinctly less pleasant phrase to visually parse correctly.)  Bummer.

Anyone know of a nifty routine that doesn't have that side effect?

And an easy, elegant way to parse out the parameter name/value pairs? 

 

david.wendelken replied on Friday, November 10, 2006

Success!

Here's some sample output showing the list of rules on the object.  My routine has automatically substituted the values from the Property name and the parameter values.

Id can not exceed 5.
Id must be unique.
Name can not exceed 10 characters.
Name is required.

Here is the way I'm storing the rule message strings in the resource file:

ruleIntegerMaxValue
{ruleProperty} can not exceed {maxValue}. 

ruleIntegerMinValue 
{ruleProperty} can not be less than {minValue}. 

ruleNoDuplicates 
{ruleProperty} must be unique. 

ruleStringMaxLength 
{ruleProperty} can not exceed {maxLength} characters. 

ruleStringRequired 
{ruleProperty} is required. 

 

I'm starting all the rule message description entries with "rule" so that they will sort together in the resources file.  The rest of the resource key is an exact match for the rule handler name.  Note: the existing Csla resource keys for the CommonRules are NOT the same as their rule handler names. :(

I'm putting on my medieval armour tomorrow and buffeting my friends about (and vice-versa), so I'll put together a  test script and post this to CSLA Contrib in the next few days.

Given that it's an extension, the rule message description entries for common rules have been duplicated in my own resource file.  I don't know enough about resource files to make my routine smart-enough to automagically look in the "right" resource file that the rule came from.  That's a bit of a problem for long-term maintenance.  Would love some pointers in the right direction... :)  

 

 

 

david.wendelken replied on Sunday, November 12, 2006

I've put the first cut of my rule extensions into the CSLA Contrib project.

Copyright (c) Marimer LLC