Home All Groups Group Topic Archive Search About

Can I hide base class properties in a derived class?

Author
23 Jan 2006 7:40 AM
Martin Widmer
Hello!

I would like to hide one property of a base class in a derived class. How
could it be done? I tried to override it with a private property, but that
doesn't seem to do the hiding.

Martin

Author
23 Jan 2006 8:20 AM
Cor Ligthert [MVP]
Martin,

>
> I would like to hide one property of a base class in a derived class. How
> could it be done? I tried to override it with a private property, but that
> doesn't seem to do the hiding.
>
I assume that you want this for by instance intelligence.

You cannot.

Have a look at the overloaded text property from the picturebox. It does
nothing and still it is there.

Cor
Author
23 Jan 2006 8:58 AM
Martin Widmer
Hi Cor

Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> schrieb im Newsbeitrag
news:%23zj7KX$HGHA.1032@TK2MSFTNGP11.phx.gbl...
> Martin,
>
>>
>> I would like to hide one property of a base class in a derived class. How
>> could it be done? I tried to override it with a private property, but
>> that doesn't seem to do the hiding.
>>
> I assume that you want this for by instance intelligence.
>
> You cannot.
>
> Have a look at the overloaded text property from the picturebox. It does
> nothing and still it is there.

Ok thanks. I will then satisfy myself with overriding it with a dummy
property who doesn't do any harm.

Martin
Author
23 Jan 2006 2:09 PM
Armin Zingler
"Martin Widmer" <martin.wid***@businessnet.de> schrieb
>
> Ok thanks. I will then satisfy myself with overriding it with a
> dummy property who doesn't do any harm.

You can also throw a 'NotSupportedException'.


Armin
Author
23 Jan 2006 2:47 PM
Herfried K. Wagner [MVP]
"Martin Widmer" <martin.wid***@businessnet.de> schrieb:
> I would like to hide one property of a base class in a derived class. How
> could it be done? I tried to override it with a private property, but that
> doesn't seem to do the hiding.

Override them with a property which has the same modifier, but specify
'Browsable' and 'EditorBrowsable' attributes on the overriding property.

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
24 Jan 2006 8:58 AM
Martin Widmer
Hi Herfried

[...]
> Override them with a property which has the same modifier, but specify
> 'Browsable' and 'EditorBrowsable' attributes on the overriding property.

Sounds promising... I am not familiar with attributes of properties in
VB.Net. Could you give me a quick example how to do that in the code?

So far I am overriding with a dummy property like this:

    Public Overrides Property Placements() As PlacementsCollection
        Get
            Throw New System.NotSupportedException
            Return Nothing
        End Get
        Set(ByVal value As PlacementsCollection)
            Throw New System.NotSupportedException
        End Set
    End Property


Martin
Author
24 Jan 2006 11:19 AM
Herfried K. Wagner [MVP]
"Martin Widmer" <martin.wid***@businessnet.de> schrieb:
>> Override them with a property which has the same modifier, but specify
>> 'Browsable' and 'EditorBrowsable' attributes on the overriding property.
>
> Sounds promising... I am not familiar with attributes of properties in
> VB.Net. Could you give me a quick example how to do that in the code?

\\\
Imports System.ComponentModel
....

<EditorBrowsable(EditorBrowsableState.Never), Browsable(False)> _
Public Overrides Property Placements() As PlacementsCollection
....
///

--
M S   Herfried K. Wagner
M V P  <URL:http://dotnet.mvps.org/>
V B   <URL:http://classicvb.org/petition/>
Author
24 Jan 2006 12:19 PM
Martin Widmer
Herfried, thanks, it's working :)

Martin
Author
23 Jan 2006 6:20 PM
Mitchell S. Honnert
Martin, this might not apply to your situation, but what about making the
scope of the base property be Friend?  This way, they wouldn't be available
outside the assembly, but could be referenced by derived classes within the
assembly.

For example, in my ID3 tag reading library, I have a base ID3TextFrame which
represents all of the frame types that have a Text property.  (An ID3 frame
is just a set of values associated to a particular metadata component, like
Artist or Comments.)  This allows me to have common code that decodes these
frame types and sets the Text property, even though in most cases, I don't
want the users of the library to access the Text property directly.

So, the base class property (ID3TextFrame.Text) is a Friend and I expose the
value with a public property in a derived class with a name and data type
that is specific to that frame.  For example, ID3TrackNumFrame.TrackNum is a
Public Short property.

Again, this may not apply to you, but it's one way to "hide" a base class
property.

Mitchell S. Honnert
www.UltraID3Lib.com


Show quoteHide quote
"Martin Widmer" <martin.wid***@businessnet.de> wrote in message
news:dr22ch$5be$1@nntp.init7.net...
> Hello!
>
> I would like to hide one property of a base class in a derived class. How
> could it be done? I tried to override it with a private property, but that
> doesn't seem to do the hiding.
>
> Martin
>
Author
24 Jan 2006 8:41 AM
Martin Widmer
Hi Mitchell

"Mitchell S. Honnert" <n***@REMhonnertOVE.com> schrieb im Newsbeitrag
news:e4Ts6mEIGHA.2900@TK2MSFTNGP14.phx.gbl...
> Martin, this might not apply to your situation, but what about making the
> scope of the base property be Friend?  This way, they wouldn't be
> available outside the assembly, but could be referenced by derived classes
> within the assembly.
[...]

I have read abotu this approach already, but my class hierarchy is quite
simple and has only 2 levels, and the base class is not abstract, I also use
it. So I cannot declare the property as friend, if I do so, it would not be
available when I instantiate members of the base class, right?

Thanks a lot

Martin