A
Arthur Dent
Hello all... I have a class which inherits from the Generic Dictionary
class.
I want to "override" the Item property. I know it is not technically
Overridable, so I marked my property as "Shadows".
Here is the relevant code...
Public Class MyClass
Inherits Dictionary(Of String, Integer)
Shadows Property Item(ByVal key As String) As Double
Get
Return If Not Me.ContainsKey(key) Then Me.Add(key, 0)
Return MyBase.Item(key)
End Get
Set(ByVal value As Double)
If Not Me.ContainsKey(key) Then Me.Add(key, 0)
MyBase.Item(key) = value
End Set
End Property
End Class
Basically, I just want that if a non-existent key is queried, it returns 0
instead of throwing an exception.
But if I run something like
Debug.Print(myClassInstance("123"))
where "123" is not a valid key, is stills throws an exception instead of
returning 0.
It throws "The given key was not present in the dictionary."
I tried adding the following attribute to my class, but it didn't help...
<DefaultProperty("Item")>
Thanks in advance, ... A.D.
class.
I want to "override" the Item property. I know it is not technically
Overridable, so I marked my property as "Shadows".
Here is the relevant code...
Public Class MyClass
Inherits Dictionary(Of String, Integer)
Shadows Property Item(ByVal key As String) As Double
Get
Return If Not Me.ContainsKey(key) Then Me.Add(key, 0)
Return MyBase.Item(key)
End Get
Set(ByVal value As Double)
If Not Me.ContainsKey(key) Then Me.Add(key, 0)
MyBase.Item(key) = value
End Set
End Property
End Class
Basically, I just want that if a non-existent key is queried, it returns 0
instead of throwing an exception.
But if I run something like
Debug.Print(myClassInstance("123"))
where "123" is not a valid key, is stills throws an exception instead of
returning 0.
It throws "The given key was not present in the dictionary."
I tried adding the following attribute to my class, but it didn't help...
<DefaultProperty("Item")>
Thanks in advance, ... A.D.