Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to hide a inherited method or property?

How to hide a inherited method or property?

Scheduled Pinned Locked Moved C#
csharptutorialquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    Wender Oliveira
    wrote on last edited by
    #1

    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

    T J D 3 Replies Last reply
    0
    • W Wender Oliveira

      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

      T Offline
      T Offline
      turbochimp
      wrote on last edited by
      #2

      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...’

      1 Reply Last reply
      0
      • W Wender Oliveira

        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

        J Offline
        J Offline
        Jesse Squire
        wrote on last edited by
        #3

        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 from System.Collections.CollectionBase instead? If the CollectionBase still exposes the method that you'd like to hide, the other solution that comes to mind would be to use the ArrayList as a private member of your class and simply wrapper the properties/methods that you'd like to expose. Hope that helps. :) --Jesse

        1 Reply Last reply
        0
        • W Wender Oliveira

          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

          D Offline
          D Offline
          Daniel Zaharia
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups