I had a quick scan around and couldn't find anywhere else to report bugs so hopefully doing it won't offend anyone (and hopefully it is a bug and I haven't missed something obvious).
I am trying to provide feedback to users about why rules are broken (why it's wrong, why they should fix it, what they should do to fix it, ...) and believe I have discovered a bug in the common rules implementations.
The code for a rule such as CommonRules.StringRequired is:
public static bool StringRequired(object target, RuleArgs e)
{
string value = (string)Utilities.CallByName(
target, e.PropertyName, CallType.Get);
if (string.IsNullOrEmpty(value))
{
e.Description = string.Format(Resources.StringRequiredRule, RuleArgs.GetPropertyName(e));
return false;
}
return true;
}
The highlighted code provides very helpful default behaviour such as "PropertyXYZ required".
Problem is that I wanted to pass in my own custom e.Description:
Dim args As New Csla.Validation.RuleArgs("PropertyXYZ")
args.Description = "Property XYZ required for ..."
ValidationRules.AddRule(AddressOf Csla.Validation.CommonRules.StringRequired, args)
It's overwritten by the 'helpful' default behaviour.
I believe the following change in the all of the common rules should help.
public static bool StringRequired(object target, RuleArgs e)
{
string value = (string)Utilities.CallByName(
target, e.PropertyName, CallType.Get);
if (string.IsNullOrEmpty(value))
{
// Provide a default Description if none was provided in the RuleArgs e
if (e.Description == string.Empty)
{
e.Description = string.Format(Resources.StringRequiredRule, RuleArgs.GetPropertyName(e));
}
return false;
}
return true;
}