JoeFallon1 posted on Saturday, January 27, 2007
The example of per type rules that relate to a specific type (not Common Rules) does not compile.
Can someone please re-write a version of this that works?
<Serializable()> _
Public Class Attendee
Inherits BusinessBase(Of Attendee)
Private mAge As Integer
Private mDrinkingBadge As Boolean
Protected Overrides Function GetIdValue() As Object
Return 1
End Function
' other code goes here
'JF fails to compile
'Protected Overrides Sub AddBusinessRules()
' ValidationRules.AddRule(AddressOf AllowedToDrink(Of Attendee), "DrinkingBadge")
'End Sub
Protected Overrides Sub AddBusinessRules()
ValidationRules.AddRule(Of Attendee)(AddressOf AllowedToDrink(Of Attendee), "DrinkingBadge")
End Sub
'JF fails to compile
'Private Shared Function AllowedToDrink(Of T)(ByVal target As T, ByVal e As Validation.RuleArgs) As Boolean
' If target.mAge < 21 AndAlso target.mDrinkingBadge Then
' e.Description = "Can not drink if under 21"
' Return False
' Else
' Return True
' End If
'End Function
'JF fails to compile - mAge is not a member of Attendee
Private Shared Function AllowedToDrink(Of Attendee)(ByVal target As Attendee, ByVal e As Validation.RuleArgs) As Boolean
If target.mAge < 21 AndAlso target.mDrinkingBadge Then
e.Description = "Can not drink if under 21"
Return False
Else
Return True
End If
End Function
' other code goes here
End Class
Joe