G
Guest
In the class below, I inherit from Generic.Dictionary so I can override
property Item. Item is not overridable, so I used Shadows, and it works as I
want. It works equally well if I replace Shadows with Overloads.
Question 1 - Which is preferred in a case like this, Shadows or Overloads.
Question 2 - The Override clan (Overrides, Overridable, NotOverridable,
MustOverride) seems to have lost some steam if I can effect an override on
something that is not declared as overridable. In other words, the totality
of what I can say with these modifiers seems to be redundant and/or
inconsistent. Or maybe not - am I paying a price that I don't know about by
using Shadows or Overloads in this way?
-------------------------
Public Class TableLookup(Of TKey, TValue)
Inherits System.Collections.Generic.Dictionary(Of TKey, TValue)
Default Public Shadows Property Item(ByVal Key As TKey) As TValue
Get
If Not ContainsKey(Key) Then Return Nothing Else Return
MyBase.Item(Key)
End Get
Set(ByVal value As TValue)
If value Is Nothing Then MyBase.Remove(Key) Else MyBase.Item(Key) =
value
End Set
End Property
End Class
property Item. Item is not overridable, so I used Shadows, and it works as I
want. It works equally well if I replace Shadows with Overloads.
Question 1 - Which is preferred in a case like this, Shadows or Overloads.
Question 2 - The Override clan (Overrides, Overridable, NotOverridable,
MustOverride) seems to have lost some steam if I can effect an override on
something that is not declared as overridable. In other words, the totality
of what I can say with these modifiers seems to be redundant and/or
inconsistent. Or maybe not - am I paying a price that I don't know about by
using Shadows or Overloads in this way?
-------------------------
Public Class TableLookup(Of TKey, TValue)
Inherits System.Collections.Generic.Dictionary(Of TKey, TValue)
Default Public Shadows Property Item(ByVal Key As TKey) As TValue
Get
If Not ContainsKey(Key) Then Return Nothing Else Return
MyBase.Item(Key)
End Get
Set(ByVal value As TValue)
If value Is Nothing Then MyBase.Remove(Key) Else MyBase.Item(Key) =
value
End Set
End Property
End Class