Suggestion for Validation Rules code

Suggestion for Validation Rules code

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


amselem posted on Monday, May 19, 2008

Hi,

I'd like to suggest adding a new delegate for validation rules that returns the result inside the eventargs, instead of returning a boolean value. So instead of this code:

Private Shared Function CheckABRule(Of T As MyBO)(ByVal target As T, ByVal e As Validation.RuleArgs) As Boolean

 If target.PropertyA > target.PropertyB Then
     
e.Description = "A must be lower than B"
     
Return False
 Else
     
Return True
 End If

End Function

We would have this little more compact code:

Private Shared Sub CheckABRule(Of T As MyBO)(ByVal target As T, ByVal e As Validation.ResultRuleArgs

     e.Description = "A must be lower than B"   
     e.Result = Not (target.PropertyA > target.PropertyB)

End Sub


What do you think?
Regards

JonnyBee replied on Monday, May 19, 2008

Or you could write the code as

Private Shared Sub CheckABRule(Of T As MyBO)(ByVal target As T, ByVal e As Validation.ResultRuleArgsAs Boolean
     e.Description = "A must be lower than B"   
    
Return Not (target.PropertyA > target.PropertyB)

End Sub

/jonnybee

amselem replied on Tuesday, May 20, 2008

Yes, that code is as compact as the one I posted but I was thinking more on following a more or less typical pattern, like System.Windows.Forms.ConvertEventArgs or System.ComponentModel.RunWorkerCompletedEventArgs. In both samples the result is returned inside the eventargs. Of course this is a matter of taste...

Copyright (c) Marimer LLC