CSLA .NET

From Rockford Lhotka's Expert C# 2005 and VB 2005 Business Objects books

Welcome to CSLA .NET Sign in | Join | Help
in Search

Suggestion for Validation Rules code

Last post 05-20-2008, 3:45 AM by amselem. 2 replies.
Sort Posts: Previous Next
  •  05-19-2008, 12:30 PM 23663

    Suggestion for Validation Rules code

    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

  •  05-19-2008, 3:16 PM 23669 in reply to 23663

    Re: Suggestion for Validation Rules code

    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
  •  05-20-2008, 3:45 AM 23684 in reply to 23669

    Re: Suggestion for Validation Rules code

    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...
View as RSS news feed in XML

Please contact Magenic for your .NET consulting and CSLA .NET mentoring needs.
Please consider making a donation to help support the ongoing development of CSLA .NET.

Make donation through PayPal - it's fast, free and secure!
Why donate?
Powered by Community Server, by Telligent Systems