Posted By: adrian.h | Sep 3rd, 2008 @ 2:12 PM
page 1 of 2
Comments: 27 | Views: 672
adrian.h
adrian.h
Would rather be camping or climbing!
How do I hide all methods/properties except the ones I wish to expose?  When I created a test app from here: http://msdn.microsoft.com/en-us/library/ms235628(VS.80).aspx and then tried to drop it into an application, it showed a myriad of choices from other classes that are part of the framework (I am assuming that is where they are coming from).

Any ideas?  Thanks.


Adrian
While other methods might exist, you can always declare your own private versions of the public methods.  That would effectively hide the public methods.  Do not forget to use the "new" keyword or you will see messages warning you that you are hiding a inherited method.  This of course is precisely what you are doing.


stevo_
stevo_
Human after all

Expose to what? intellisense? programatically? this thread is very confusing..

Dr Herbie
Dr Herbie
Horses for courses
If you're creating a custom control then you shouldn't be trying to hide the methods and properties inherited from the base class -- they're needed for the control to interact with it's container and the rest of the .NET UI framework.

Are there specific methods you don't think you need?

Herbie

EDIT:  Just seen you reply -- you can always create a new interface with just the methods you want programmers to see and add that the the control inheritance, after the base class inheritance.  Then just tell developers to use the interface?
Microsoft didn't done .NET Framework only for you, did they? Those classes are general purpose and are made to fill many possible scenarios, that's why there is a lot of stuff in there, if you don't like the threshold they add why don't you make your own Control class and do all the heavy lifting by yourself?
Sven Groot
Sven Groot
My name has 9 letters. Coincidence? I think not...
But you can still do that in .Net. Just create an interface and implement it in your class.
littleguru
littleguru
<3 Seattle
In C# (don't confuse that with .NET) by default all member fields are private. Methods and properties are public. That's the convention.

Now you could create interfaces that are then going to be implemented by your classes. You could then make the classes internal (which means only visible inside the assembly - library or .exe) and the interfaces public. The next step would be a way (a factory pattern perhaps) that allows creating instances of these classes that are returned as the interface that they implement. This allows people to create instances of the them from outside of your assembly.
Bas
Bas
It finds lightbulbs.
A class with 70 public methods and 80 public properties is a pretty horribly designed class in the first place.
stevo_
stevo_
Human after all
Also note the difference between explicit and implicit member implementations with interfaces.. I'm really not sure why you need a decorator / proxy pattern to simply make a class..
Sven Groot
Sven Groot
My name has 9 letters. Coincidence? I think not...
What do you need a proxy class for? Just use an interface.

EDIT: Strike that, just check my next post. It seems we've finally managed to uncover what you're trying to do and what your problem is.
Sven Groot
Sven Groot
My name has 9 letters. Coincidence? I think not...
Now we're getting somewhere. If I understand you, you're creating a Form inside a class library, and want to export it, but you don't want the user of the class library to have access with all the default methods of the Form class.

In that specific case I would recommend you do make a "proxy" class and keep the Form itself internal to the class library.
Sven Groot
Sven Groot
My name has 9 letters. Coincidence? I think not...
I don't see how that applies. The form doesn't change (except it's no longer public), the designer doesn't care.
Sven Groot
Sven Groot
My name has 9 letters. Coincidence? I think not...
Wait, you want to export a control, and have it be usable in the designer? Earlier you were saying you wanted to export a form (again you're mixing terminology).

In that case you must export the whole thing, including all inherited methods (Windows Forms needs them to make the control work, and the designer needs them to). .Net developers will also expect all those methods to be there. The fact that they're there is a good thing. You shouldn't hide anything, and you definitely don't need any proxy class in this case.
Sven Groot
Sven Groot
My name has 9 letters. Coincidence? I think not...
ActiveX controls and .Net custom controls are entirely different beasts. You can't really compare them at all, except that they sort of serve the same purpose.
PerfectPhase
PerfectPhase
"This is not war, this is pest control!" - Dalek to Cyberman


As it happens a Form is just a speciallised Control, but that's another matter.

For what you want to do, which for your reasons seems to me is quite pointless but each to their own,  I'd bodge it like this....

<BR>public interface IMyCustomControl<BR>{<BR>   bool ClickAnywhere { get; set; }<BR>}</P>
<P>public partial class UserControl1 : UserControl, IMyCustomControl<BR>{<BR>   public UserControl1()<BR>   {<BR>      InitializeComponent();<BR>   }</P>
<P>   #region IMyCustomControl Members</P>
<P>   public bool ClickAnywhere<BR>   {<BR>      get<BR>      {<BR>         throw new NotImplementedException();<BR>      }<BR>      set<BR>      {<BR>         throw new NotImplementedException();<BR>      }<BR>   }</P>
<P>   #endregion<BR>}</P>
<P> public partial class Form1 : Form<BR>  {<BR>      public Form1()<BR>      {<BR>         InitializeComponent();<BR>      }</P>
<P>      private void Form1_Load(object sender, EventArgs e)<BR>      {<BR>         IMyCustomControl cc = new UserControl1();<BR>         cc.ClickAnywhere = true   //Only see the one method in intellisense<BR>         this.Controls.Add(cc as UserControl);<BR>      }<BR> }</P>
<P>

page 1 of 2
Comments: 27 | Views: 672
Microsoft Communities