|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Can I hide base class properties in a derived class?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 Martin,
> I assume that you want this for by instance intelligence.> 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. > You cannot. Have a look at the overloaded text property from the picturebox. It does nothing and still it is there. Cor Hi Cor
Show quoteHide quote "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> schrieb im Newsbeitrag Ok thanks. I will then satisfy myself with overriding it with a dummy 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. property who doesn't do any harm. Martin "Martin Widmer" <martin.wid***@businessnet.de> schrieb You can also throw a 'NotSupportedException'.> > Ok thanks. I will then satisfy myself with overriding it with a > dummy property who doesn't do any harm. Armin "Martin Widmer" <martin.wid***@businessnet.de> schrieb: Override them with a property which has the same modifier, but specify > 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. '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/> Hi Herfried
[...] > Override them with a property which has the same modifier, but specify Sounds promising... I am not familiar with attributes of properties in > 'Browsable' and 'EditorBrowsable' attributes on the overriding property. 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 "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/> 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 > Hi Mitchell
"Mitchell S. Honnert" <n***@REMhonnertOVE.com> schrieb im Newsbeitrag I have read abotu this approach already, but my class hierarchy is quite 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. [...] 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
Hepl! No accessible 'Main' method with an appropriate signature was found ...
Q: primary key OK....forget the code...how about some pointers? Multithreading Problem with objects and automatic numbering in VB.NET executing a .dll? .NET 2.0 question ? Reading from the COM Port stopping a process How to Make A small word like editor, |
|||||||||||||||||||||||