Rules for non-existant Property

Rules for non-existant Property

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


JoeFallon1 posted on Thursday, June 14, 2007

Can I create a strongly typed rule within a class and "assign" it to a non-existant property of the class like this? There is no Boolean Property named NoneChecked in my class. I simply want to check if one of the other 4 Boolean properties has been checked. I did this a lot in CSLA 1.x - just want to know if there is any problem with it in 2.0.

    Protected Overrides Sub AddBusinessRules()    
      'NoneChecked
      ValidationRules.AddRule(Of MyBO, MyRuleArgs)(AddressOf AtLeastOneIsChecked, New MyRuleArgs("NoneChecked"))
    End Sub

    Private Shared Function AtLeastOneIsChecked(Of T As MyBO, R As MyRuleArgs)(ByVal target As T, ByVal e As R) As Boolean
      If Not (target.mChkCode OrElse target.mChkDesc OrElse target.mChkGrp OrElse target.mChkStatus) Then
        e.Description = "You must check at least one of the checkboxes."
        Return False
      Else
        Return True
      End If
    End Function

Joe

xal replied on Thursday, June 14, 2007

No problem. You need to call ValidationRules.CheckRules("NoneChecked") at some point though.
I usually do it inside OnPropertyChanged().

Andrés

JoeFallon1 replied on Thursday, June 14, 2007

Thanks - that's what I wanted to know.

I do call ValidationRules.CheckRules("NoneChecked") at least once.

Joe

 

Copyright (c) Marimer LLC