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

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?
 
M

Mick Doherty

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
 
M

Mick Doherty

I spotted it :)

Public Shadows ReadOnly Property Count() As Integer
Get
End Get <---
End Property
 
M

Marina

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"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top