I have a rule here:
private bool IsValidEmailAddress(object target, Csla.Validation.RuleArgs e)
{
if (!Regex.IsMatch(_address, "\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*"))
{
e.Description = Resources.InvalidEmailFormat;
return false;
}
return true;
}
Nothing too flashy. I've got to admit I'm not entirely sure I understand, after reading the release notes, whether I need to give additional attention to this rule when moving to 2.1.
It appears that everything immediately works fine after moving to 2.1, but I have seen notes discussing using static rule methods for type rules, and my rule is still an instance method.
I'm going to dig into some of the old posts but if someone is able to articulate the needed modifications when moving to 2.1, I'd appreciate it!
OK, I think I understand what you're saying. That's a tricky one. It's a good thing I'm in a process that has me visiting all of my classes anyways.
Taking what you said, let me throw out what I've changed it to - is this in the right spirit?
/// <summary>
/// Method to add custom validation rules that are not generated.
/// </summary>
private void AddCustomRules()
{
// Email address needs to be the appropriate format.
ValidationRules.AddRule<EmailAddress>(IsValidEmailAddress, "Address");
}
/// <summary>
/// Validation rule to test the format of the e-mail address.
/// </summary>
private static bool IsValidEmailAddress(EmailAddress target, Csla.Validation.RuleArgs e)
{
if (!Regex.IsMatch(target._address, "\\w+([-+.']\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*"))
{
e.Description = Resources.InvalidEmailFormat;
return false;
}
return true;
}
I'm using partial classes with the C# templates - so AddBusinessRules() is declared in the generated code, and then uses a delegate and that's where my method comes into play - adding business rules that aren't supported by the generated code from the templates at this point.
Thanks for the input!
I generate it from the C# CodeSmith templates with some modifications.
I use the XML source option, which isn't the primary option, but it allows me to be a little bit more robust on what I can do with it, including such things as "property include files" to include "base class properties" for multiple concrete classes instead of duplicating them, provide means to add XML attributes for summary and remarks comments so my gen code is documented, etc. I just think the XML route is long term a little more powerful.
I had dreams of it generating the stored procedures for me too but I've set it aside for now. I did not take the CSLA Gen approach at the time because it seemed like the Codesmith C# templates were more widely adopted and also because I don't think there were C# 2.0 templates available for CSLA Gen at the time.
Copyright (c) Marimer LLC