CommonRules not double-checking Arguments?

CommonRules not double-checking Arguments?

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


david.wendelken posted on Monday, December 17, 2007

I was looking at the 3.x CommonRules library in detail for the first time today. (I've been using my internally developed version based on the 2.x version until now.)

Here's a snippet of code:

[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1062:ValidateArgumentsOfPublicMethods")]
public static bool StringMaxLength(object target, RuleArgs e)
{
    DecoratedRuleArgs args = (DecoratedRuleArgs)e;

    int
max = (int)args["MaxLength"];

That last line assumes the presence of a MaxLength parameter.  If the programmer forgot to code it or spelled the parameter name wrong, it won't produce a nice error message.

I guess that's ok, but it surprised me a bit.  

david.wendelken replied on Monday, December 17, 2007

On the plus side, it took me about 20 minutes to figure out how to convert my first rule to use DecoratedRuleArgs.  It's taking me about 3 minutes apiece to convert them now. ;)

JoeFallon1 replied on Monday, December 17, 2007

David,

1. What did you do to resolve the potential exception?

2. Want to save us all 17 minutes and explain what to do when setting these up?

Joe

 

david.wendelken replied on Tuesday, December 18, 2007

JoeFallon1:

1. What did you do to resolve the potential exception?

Well, I looked at the prior version of CommonRules and realized it did the same thing.  Figured it must not have been a problem after all, since I just noticed it after 21 months of working with CSLA. :)

JoeFallon1:

2. Want to save us all 17 minutes and explain what to do when setting these up?

Be glad to, but it won't be until tomorrow afternoon.  On my way home to chase my wife around the house. :)   Meetings all morning long. :(

 

Copyright (c) Marimer LLC