You certainly can create your own Common Rules
module/class. You can even take CommonRules.StringRequired as a basis for
your own rule “LastNameRule”. I personally think that this is
a good idea. The only thing I would suggest is not to make these rules
any BO specific, but create them generically just like Common Rules. This
way you will not couple unrelated objects.
Ex:
Public Function LastNameRule( _
ByVal target As Object, ByVal e
As RuleArgs) As Boolean
Dim value As String = _
CStr(CallByName(target, e.PropertyName, CallType.Get))
If Len(value) = 0 Then
e.Description = _
String.Format(My.Resources.StringRequiredRule, RuleArgs.GetPropertyName(e))
Return False
Else
If
value.Lenght>20
e.
Description = My.Resource.LastNameRuleTooLong ‘ or some other message
Return False
Else
Return
True
End
If
End If
End Function
Sergey Barskiy
Senior Consultant
office: 678.405.0687 |
mobile: 404.388.1899
![cid:_2_0648EA840648E85C001BBCB886257279]()
Microsoft Worldwide Partner of the Year | Custom
Development Solutions, Technical Innovation
From: JohnB
[mailto:cslanet@lhotka.net]
Sent: Monday, May 12, 2008 3:13 PM
To: Sergey Barskiy
Subject: [CSLA .NET] Sharing Validation Rules
Some time ago I thought that someone posted about this topic
but I have been unable to find the article I'm thinking about. Basically I
would like to know if it is possible and/or advisable to share validation rules
across objects.
For example, let's assume that I have several objects that have a 'LastName'
property and I would like to make sure that 1) Last name is always required and
2) The length of last name can not exceed say 20 characters.
I can easily do this in one object and also copy and paste to any other objects
that use LastName but I would like to create maybe one global place to store
these 'common' validations.
Any ideas?
Thanks,