##DIRECTIVE START_TAG=<% END_TAG=%> ##DIRECTIVE MAP_TYPE String=String ##DIRECTIVE MAP_TYPE Integer=Integer ##DIRECTIVE MAP_TYPE Long=Integer ##DIRECTIVE MAP_TYPE Double=Double ##DIRECTIVE MAP_TYPE Date=Date ##DIRECTIVE MAP_TYPE Boolean=Boolean ##DIRECTIVE MAP_TYPE Variant=Object ##DIRECTIVE MAP_TYPE Object=Object ##DIRECTIVE MAP_TYPE Decimal=Decimal ' 'ClassGenerator Template Version 01.00.00 ' Public Class <%CLASS_NAME%>Dictionary Inherits DictionaryBase Protected Const ITEM_TYPE As String = "<%PROJECT_NAME%>.<%CLASS_NAME%>" Default Public Property Item(key As Object) As <%CLASS_NAME%> Get Return CType(Dictionary(key), <%CLASS_NAME%>) End Get Set Dictionary(key) = value End Set End Property Public ReadOnly Property Keys() As ICollection Get Return Dictionary.Keys End Get End Property Public ReadOnly Property Values() As ICollection Get Return Dictionary.Values End Get End Property Public Sub Add(key As Object, value As <%CLASS_NAME%>) Dictionary.Add(key, value) End Sub Public Function Contains(key As Object) As Boolean Return Dictionary.Contains(key) End Function Public Sub Remove(key As Object) Dictionary.Remove(key) End Sub Protected Overrides Sub OnInsert(ByVal key As Object, ByVal value As Object) If ValidateKeyObjectType(key, "key must be of type " & ITEM_TYPE, "key") Then ValidateKeyObjectData(key, "key must not be null or empty string.", "key") End If If ValidateValueObjectType(value, "value must be of type " & ITEM_TYPE, "value") Then ValidateValueObjectData(value, "value must not be null", "value") End If End Sub Protected Overrides Sub OnRemove(ByVal key As Object, ByVal value As Object) If ValidateKeyObjectType(key, "key must be of type " & ITEM_TYPE, "key") Then ValidateKeyObjectData(key, "key must not be null or empty string.", "key") End If End Sub Protected Overrides Sub OnSet(ByVal key As Object, ByVal oldValue As Object, ByVal newValue As Object) If ValidateKeyObjectType(key, "key must be of type " & ITEM_TYPE, "key") Then ValidateKeyObjectData(key, "key must not be null or empty string.", "key") End If If ValidateValueObjectType(newValue, "value must be of type " & ITEM_TYPE, "newValue") Then ValidateValueObjectData(newValue, "value must not be null", "newValue") End If End Sub Protected Overrides Sub OnValidate(ByVal key As Object, ByVal value As Object) If ValidateKeyObjectType(key, "key must be of type " & ITEM_TYPE, "key") Then ValidateKeyObjectData(key, "key must not be null or empty string.", "key") End If If ValidateValueObjectType(value, "value must be of type " & ITEM_TYPE, "value") Then ValidateValueObjectData(value, "value must not be null", "value") End If End Sub Protected Function ValidateKeyObjectType(ByVal key As Object, ByVal ExceptionMessage As String, ByVal ParameterName As String) As Boolean ' If Not key.GetType() Is Type.GetType(ITEM_TYPE) Then ' Throw New ArgumentException(ExceptionMessage, ParameterName) ' End If Return True End Function Protected Function ValidateKeyObjectData(ByVal key As Object, ByVal ExceptionMessage As String, ByVal ParameterName As String) As Boolean 'Dim ValueObj As <%CLASS_NAME%> = CType(key, <%CLASS_NAME%>) If key Is Nothing OrElse key.ToString.Length = 0 Then Throw New ArgumentException(ExceptionMessage, ParameterName) End If Return True End Function Protected Function ValidateValueObjectType(ByVal value As Object, ByVal ExceptionMessage As String, ByVal ParameterName As String) As Boolean If Not value.GetType() Is Type.GetType(ITEM_TYPE) Then Throw New ArgumentException(ExceptionMessage, ParameterName) End If Return True End Function Protected Function ValidateValueObjectData(ByVal value As Object, ByVal ExceptionMessage As String, ByVal ParameterName As String) As Boolean 'Dim ValueObj As <%CLASS_NAME%> = CType(value, <%CLASS_NAME%>) 'If value Is Nothing OrElse value.ToString.Length = 0 Then ' Throw New ArgumentException(ExceptionMessage, ParameterName) 'End If Return True End Function End Class