Suggested upgrade to CommonRules.IntegerMinValue

Suggested upgrade to CommonRules.IntegerMinValue

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


snesbitt posted on Tuesday, June 05, 2007

I am using 2.1.4 and would like to suggest a minor enhancement to the CommonRules.IntegerMinValue rule.  The way it is currently coded, the int value of the property is obtained from the object using:

int value = (int)Utilities.CallByName(target, e.PropertyName, CallType.Get);

If the property in question is a short (Int16) instead of int (Int32) there is a runtime error because the value cannot be unboxed in this way.  An alternative which works with a Int16 property is to use Convert.ToInt32().

However, to make this rule suitable and reusable for the 16, 32 and 64bit numeric values, I suggest creating a new rule called NumericMinValue and NumericMaxValue, with corresponding RuleArgs classes that accept Int64 values intead of int.  Using Convert.ToInt64() in this implementation will allow short, int and long properties to evaluated with the one CommonRule.

I have created a custom rule in my project to support this, but I think this has value if it is part of the core framework.  Any chance this can sneak into 3.0?

William replied on Wednesday, June 06, 2007

You can use the generic version:

Regards,
William

snesbitt replied on Wednesday, June 06, 2007

Thank you - I can't believe I didnt notice those rules yesterday Embarrassed [:$]

Copyright (c) Marimer LLC