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 base class method

how to hide base class method

Scheduled Pinned Locked Moved C#
visual-studiotutorialquestion
8 Posts 5 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.
  • C Offline
    C Offline
    CiNN
    wrote on last edited by
    #1

    how do you hide unsupported method from a base class ? so that they don't show up in intellisense.

    Steve EcholsS U C 4 Replies Last reply
    0
    • C CiNN

      how do you hide unsupported method from a base class ? so that they don't show up in intellisense.

      Steve EcholsS Offline
      Steve EcholsS Offline
      Steve Echols
      wrote on last edited by
      #2

      Make them private.


      - S 50 cups of coffee and you know it's on!

      • S
        50 cups of coffee and you know it's on!
        Code, follow, or get out of the way.
      1 Reply Last reply
      0
      • C CiNN

        how do you hide unsupported method from a base class ? so that they don't show up in intellisense.

        Steve EcholsS Offline
        Steve EcholsS Offline
        Steve Echols
        wrote on last edited by
        #3

        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!

        • S
          50 cups of coffee and you know it's on!
          Code, follow, or get out of the way.
        P V 2 Replies Last reply
        0
        • Steve EcholsS Steve Echols

          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!

          P Offline
          P Offline
          Paul Conrad
          wrote on last edited by
          #4

          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

          1 Reply Last reply
          0
          • Steve EcholsS Steve Echols

            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!

            V Offline
            V Offline
            Vikram A Punathambekar
            wrote on last edited by
            #5

            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.

            P 1 Reply Last reply
            0
            • V Vikram A Punathambekar

              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.

              P Offline
              P Offline
              Paul Conrad
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              • C CiNN

                how do you hide unsupported method from a base class ? so that they don't show up in intellisense.

                U Offline
                U Offline
                Urs Enzler
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                • C CiNN

                  how do you hide unsupported method from a base class ? so that they don't show up in intellisense.

                  C Offline
                  C Offline
                  CiNN
                  wrote on last edited by
                  #8

                  okay

                  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