How can a property be Overridable and NotOverridable at the same time?

  • Thread starter Thread starter Marina
  • Start date Start date
M

Marina

Hi,

I have a class that inherits from CollectionBase, and I'm trying to override
its Count property. As per the documentation, this property is overridable -
so I should be able to do this. So this is my code:

Public Overrides ReadOnly Property Count() As Integer
Get
End Get
End Property

The message I am getting is:
'Public Overrides ReadOnly Property Count() As Integer' cannot override
'Public Overridable NotOverridable ReadOnly Property Count() As Integer'
because it is declared 'NotOverridable'.


According to this, Count is both Overridable and NotOverridable? And the
NotOverridable is winning?

Can anyone shed any light on this?
 
Your right. It should be either/or not both.
In any case you can shadow it.

Public Shadows ReadOnly Property Count() As Integer
Get
Set
End Property
 
I spotted it :-)

Public Shadows ReadOnly Property Count() As Integer
Get
End Get <---
End Property
 
Yes, the problem is, anything that excepts an icollection (like a grid or
something), will not be able to use the shadowed version.

Anyway, it seems like a stranger compiler and documentation bug - since
clearly this property is not overridable as the documentation claims.

Probably better off just implementing ICollection instead of inheriting
collectionbase at this point...

"Mick Doherty"
 
Back
Top