How to hide a inherited method or property?
-
Hello, just look this class. public class MyClass : ArrayList { public MyClass () {} public override int Add(object value) { return base.Add (value); } } right, how to hide this method or make it private? I don't want to see this method at intelisense when I call MyClass methods and properties. tkx Wender Oliveira .NET Programmer
-
Hello, just look this class. public class MyClass : ArrayList { public MyClass () {} public override int Add(object value) { return base.Add (value); } } right, how to hide this method or make it private? I don't want to see this method at intelisense when I call MyClass methods and properties. tkx Wender Oliveira .NET Programmer
I don't think there is any way to hide the method in the manner you describe, and since it is a virtual method of the base (ArrayList) class, there's not really a way to obscure it - the accessibility of public virtual members can't be altered by the inheriting class. The framework doesn't allow partial implementation inheritance. You could, however, change the behavior of your overridden version of the
Add
method to keep it from doing anything. Perhaps a better option might be to create a new class that employs an ArrayList as a private field. You would then be free to manipulate the contents of the ArrayList at your discretion. Of course you lose some polymorphic benefits by doing so. You could also create a new Collection-type class (Add
is not a member of the ICollection interface).The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
-
Hello, just look this class. public class MyClass : ArrayList { public MyClass () {} public override int Add(object value) { return base.Add (value); } } right, how to hide this method or make it private? I don't want to see this method at intelisense when I call MyClass methods and properties. tkx Wender Oliveira .NET Programmer
As far as I'm aware, it isn't possible to hide a public method inherited from a class lower in the hierarchy. I'm not sure if the
ArrayList
as a base class was just for example purposes, but have you looked at derriving fromSystem.Collections.CollectionBase
instead? If theCollectionBase
still exposes the method that you'd like to hide, the other solution that comes to mind would be to use theArrayList
as a private member of your class and simply wrapper the properties/methods that you'd like to expose. Hope that helps. :) --Jesse -
Hello, just look this class. public class MyClass : ArrayList { public MyClass () {} public override int Add(object value) { return base.Add (value); } } right, how to hide this method or make it private? I don't want to see this method at intelisense when I call MyClass methods and properties. tkx Wender Oliveira .NET Programmer
Maybe EditorBrowsableAttribute can help you. It can be use to hide a member of a class from IntelliSense. int ageval; [EditorBrowsable(EditorBrowsableState.Never)] public int Age { get { return ageval; } set { if (!ageval.Equals(value)) { ageval = value; } } } Daniel.