|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Hide members in a derived classWith the following code, a class that derives from DerivedClass can still see the member "Name" in the base class. Can anyone provide me with an example that will do what I need? Public Class BaseClass Private mName As String = "Bob" Public Overridable Function Name() As String Name = mName End Function End Class Public Class DerivedClass : Inherits BaseClass Private Shadows Function Name() As String Name = "Joe" End Function End Class -------------------------------- Thanks, Paul Wu Paul,
No you can't. You will see this behaviour as well in some of the standard controls who derive from control. Some members do just nothing. I hope this helps anyhow, Cor Classes will always have the methods and properties they were created with. You cannot hide these from code but you can hide them from the eyes of your users if you know what you're doing.
In the case of a class that is examined at design-time by the property grid you can hide classes by creating a designer for your class and overriding the PreFilterProperties or PostFilterProperties methods. These take the list of properties obtained by reflection and remove enable you to add or rmove property descriptors. This is how the Browsable attribute works to enable certain properties to be visible at design time. The trick of overriding the class and marking a property as browseable or not is also a possibility for design-time usage but is IMO not quite so desirable. If you're code presents properties in some other way at runtime, perhaps through the property grid or some other form of reflection, you can make your class implement ICustomTypeDescriptor. This interface enables you to preemptively filter properties and can be used at runtime without a designer. -- Bob Powell [MVP] Visual C#, System.Drawing Find great Windows Forms articles in Windows Forms Tips and Tricks http://www.bobpowell.net/tipstricks.htm Answer those GDI+ questions with the GDI+ FAQ http://www.bobpowell.net/faqmain.htm All new articles provide code in C# and VB.NET. Subscribe to the RSS feeds provided and never miss a new article. "Paul Wu" <pwu@spam.encorecredit.com> wrote in message news:un24VZVQFHA.576@TK2MSFTNGP15.phx.gbl... Is there a way to constract a derived class that hides certain public members of a base class ?With the following code, a class that derives from DerivedClass can still see the member "Name" in the base class. Can anyone provide me with an example that will do what I need? Public Class BaseClass Private mName As String = "Bob" Public Overridable Function Name() As String Name = mName End Function End Class Public Class DerivedClass : Inherits BaseClass Private Shadows Function Name() As String Name = "Joe" End Function End Class -------------------------------- Thanks, Paul Wu Bob,
>In the case of a class that is examined at design-time by the property grid I wrote this in a way like you as well and deleted that again, because it is >you can hide >classes by creating a designer etc. for somebody who create classes in my opinion not interesting. The chalenge is in my opinon to let the members never (directly) been showed in a derived class . (With directly I mean without casting). When you have a solution for that, than I will be glad when you can show that and do I probably miss something. Cor The only sensible way to do what you're suggesting is to use the memento
pattern... Otherwise, the suggestions I made are the only possible alternatives. -- Show quoteHide quoteBob Powell [MVP] Visual C#, System.Drawing Find great Windows Forms articles in Windows Forms Tips and Tricks http://www.bobpowell.net/tipstricks.htm Answer those GDI+ questions with the GDI+ FAQ http://www.bobpowell.net/faqmain.htm All new articles provide code in C# and VB.NET. Subscribe to the RSS feeds provided and never miss a new article. "Cor Ligthert" <notmyfirstn***@planet.nl> wrote in message news:%23JScstZQFHA.2348@tk2msftngp13.phx.gbl... > Bob, > >>In the case of a class that is examined at design-time by the property >>grid you can hide >classes by creating a designer etc. > > I wrote this in a way like you as well and deleted that again, because it > is for somebody who create classes in my opinion not interesting. > > The chalenge is in my opinon to let the members never (directly) been > showed in a derived class . (With directly I mean without casting). > > When you have a solution for that, than I will be glad when you can show > that and do I probably miss something. > > Cor >
Help with Debugging
Paging by example - help - still no luck.... Get processes list problem (win 2000) Reading an XML file into a Dataset - problem Custom Collections : overriding toString Response.Redirect("WebForm1.aspx") Sharing references/members Web Application using VB.NET VB.net Ablauf vom packen eines Projekts Javascriptng Properties |
|||||||||||||||||||||||