About DecoratedRuleArgs ToString() override.

About DecoratedRuleArgs ToString() override.

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


rxelizondo posted on Monday, November 02, 2009

Hi guys.


This is pretty much a stupid post and it’s probably not worth wasting bandwidth to post this but just throwing it out there.


Consider this:


var args = new Csla.Validation.DecoratedRuleArgs(NameProperty);
args["MaxLength"] = 50;
args["Format"] = "000.00";
ValidationRules.AddRule(Csla.Validation.CommonRules.StringMaxLength, args);


Now consider this (The properties are initialized in the opposite order):


var args = new Csla.Validation.DecoratedRuleArgs(NameProperty);
args["Format"] = "000.00";
args["MaxLength"] = 50;
ValidationRules.AddRule(Csla.Validation.CommonRules.StringMaxLength, args);



Inside the DecoratedRuleArgs ToString() override, there is a loop used to concatenate the properties names that goes something like this:


foreach (System.Collections.Generic.KeyValuePair item in _decorations)
{
...
}


Basically this means that the ToString() method on DecoratedRuleArgs could return “MaxLength=50& Format=000.00” on the firs example and “Format=000.00&MaxLength=50” in the other.


Strictly speaking, as far as I can tell, this behavior is inconsequential from the CSLA functionality point of view, but from the consistency point of view, I wonder if the ToString() should sort the properties first before concatenating them so we can get a consistent output no matter how the properties are initialized.


Again, I realize it’s a dumb post but I am just kind of picky about this sort of things. No biggie, just a call out. Don’t hate me for waiting your time reading this!!


Cheers.

RockfordLhotka replied on Monday, November 02, 2009

The idea is that you'll use the RuleDescriptor class (works like System.Uri) to parse the rule:// URI and interact with its components.

Just like with a web URL, order of parameters shouldn't matter, because you should get them via a parser that allows you to ask for them by name.

Copyright (c) Marimer LLC