Validation in child objectsValidation in child objects
Old forum URL: forums.lhotka.net/forums/t/7910.aspx
neste posted on Thursday, October 29, 2009
Hello -
I've just started using the CSLA framework - and I need some guidance on how to tackle the following issue:
I have a Customer business object that has two address child objects: physical and mailing. The validation rules for the physical address are different from the mailing address. I created an Address class on which I set an AddressType field to differentiate between the two. How do I add business rules to the Address class that would differ between the two address types? Shared rules would not work.
Any help is much appreciated! Thank you.
Henrik replied on Thursday, October 29, 2009
Create a validation rule method in the address class that branches on the address type, like in the example below:
private static bool RequireZipCode(T target, Csla.Validation.RuleArgs e) where T : Address
{
if (target.ReadProperty(AddressTypeProperty) == "Mailing")
{
//Rule for mailing address
}
else
{
//Rule for physical address
}
return true;
}
Cheers
/Henrik
PS. How do I post formatted code?neste replied on Thursday, October 29, 2009
Thanks for the tip, Henrik. I'll try that.
Copyright (c) Marimer LLC