业务验证代码的框架结构
业务验证处理委托:
Public Delegate Function RuleHandler(byval target as Object, byval e as RuleArgs) as Boolean
target:要处理的数据对象
e:验证规则参数,该参数将指导验证方法的执行。该参数至少包含:target上需要验证的数据项名称,以及其它验证条件
<Serializable()>Public Class RuleArgs
Private mPropertyName as String
Public ReadOnly Property PropertyName() as String
Get
Return mPropertyName
End Get
End Property
Public Sub New(byval propertyName as String)
mPropertyName = propertyName
End Sub
End Class
建立验证规则管理器,验证规则管理器通过“验证名称”来管理验证规则(就要使用到HybridDictionary),对验证的管理至少包含添加验证,执行验证。
Public Class RulesManage
'添加验证规则,所有的验证规则都由HybridDictionary来保存
Public Sub AddRule(byval handler as RuleHandler, byval rulename as String, byval ruleArgs as RuleArgs)
'执行验证,验证的执行通过保存在HybridDictionary中的RuleHandler来完成,对target的处理由ruleName来指导,而ruleName和RuleArgs对应,RuleArgs中包含了验证数据的名称及其它验证条件
Public Sub CheckRules(byval target as Object, byval ruleName as String)
End Sub