業務驗證代碼的架構結構
業務驗證處理委託:
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