how to hide base class method
-
how do you hide unsupported method from a base class ? so that they don't show up in intellisense.
Make them private.
- S 50 cups of coffee and you know it's on!
-
how do you hide unsupported method from a base class ? so that they don't show up in intellisense.
Hmmm, after further research, I don't think you can. I thought this would do it:
public class ClassA { public void DoStuff( ) { } } public class ClassB : ClassA { private new void DoStuff( ) { } }
But the ClassA's DoStuff is still accessible. I tried this too:
public class ClassA { public void DoStuff( ) { } } public class ClassB : ClassA { \[Obsolete\] public new void DoStuff( ) { } }
But that just tells you that the method is depricated in intellisense.
- S 50 cups of coffee and you know it's on!
-
Hmmm, after further research, I don't think you can. I thought this would do it:
public class ClassA { public void DoStuff( ) { } } public class ClassB : ClassA { private new void DoStuff( ) { } }
But the ClassA's DoStuff is still accessible. I tried this too:
public class ClassA { public void DoStuff( ) { } } public class ClassB : ClassA { \[Obsolete\] public new void DoStuff( ) { } }
But that just tells you that the method is depricated in intellisense.
- S 50 cups of coffee and you know it's on!
Steve Echols wrote:
just tells you that the method is depricated in intellisense
You could just put it there to kind of shoo people away from it. Get them thinking "I better not use this method, it might not be there in the next release of the class"
"I've seen more information on a frickin' sticky note!" - Dave Kreskowiak
-
Hmmm, after further research, I don't think you can. I thought this would do it:
public class ClassA { public void DoStuff( ) { } } public class ClassB : ClassA { private new void DoStuff( ) { } }
But the ClassA's DoStuff is still accessible. I tried this too:
public class ClassA { public void DoStuff( ) { } } public class ClassB : ClassA { \[Obsolete\] public new void DoStuff( ) { } }
But that just tells you that the method is depricated in intellisense.
- S 50 cups of coffee and you know it's on!
The question isn't clear. Does he want the method hidden to the subclass or to the outside world? Of course, he can opt to implement the method anyway and have it throw a NotSupportedException.
Cheers, Vıkram.
After all is said and done, much is said and little is done.
-
The question isn't clear. Does he want the method hidden to the subclass or to the outside world? Of course, he can opt to implement the method anyway and have it throw a NotSupportedException.
Cheers, Vıkram.
After all is said and done, much is said and little is done.
Vikram A Punathambekar wrote:
implement the method anyway and have it throw a NotSupportedException
I never thought of that. Could be done.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
-
how do you hide unsupported method from a base class ? so that they don't show up in intellisense.
You can't hide the method from the base class. Actually this is because of OO design principles: the derived class can only extend the interface not narrow it. Maybe you should work with two different interfaces - one for your base class and one for your derived class. btw: yes I know that in the .NET framework there are subclasses that do not fulfill the interface of the base class (some UI controls have this behaviour, but I can't remember which ones at the moment).
-^-^-^-^-^- no risk no funk
-
how do you hide unsupported method from a base class ? so that they don't show up in intellisense.