Hiding functions like ToString

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Torben Laursen

    Hiding functions like ToString

    Hi

    I have a class that I use in Excel to define some custom functions.
    The problem that I have is that the class also has some building functions
    that for some reason is there:
    ToString
    GetType
    GetHashCode
    Equals

    They show up inside Excel and that is not good since my customers has no
    need for them.
    I have tryed to hide them using code like:
    private new string ToString()

    {

    return "";

    }

    But that has no effect.

    The class is defined as:

    [ClassInterface( ClassInterfaceT ype.AutoDual)]

    public class Functions

    Can anyone show me how to hide these buildin functions?

    Thanks Torben




  • Jacob

    #2
    Re: Hiding functions like ToString

    Every class that derives from the object class has these methods.
    There's nothing you can do about it.


    Torben Laursen wrote:
    Hi
    >
    I have a class that I use in Excel to define some custom functions.
    The problem that I have is that the class also has some building functions
    that for some reason is there:
    ToString
    GetType
    GetHashCode
    Equals
    >
    They show up inside Excel and that is not good since my customers has no
    need for them.
    I have tryed to hide them using code like:
    private new string ToString()
    >
    {
    >
    return "";
    >
    }
    >
    But that has no effect.
    >
    The class is defined as:
    >
    [ClassInterface( ClassInterfaceT ype.AutoDual)]
    >
    public class Functions
    >
    Can anyone show me how to hide these buildin functions?
    >
    Thanks Torben

    Comment

    • Morten Wennevik [C# MVP]

      #3
      Re: Hiding functions like ToString

      Hi Torben,

      I may be wrong on this, but I would find it odd if you could hide these
      methods as they are essential to .Net and are defined in System.Object. I
      think you need to rewrite the Excel class to ignore those names.


      On Tue, 23 Jan 2007 10:51:31 +0100, Torben Laursen
      <Torben@newsgro ups.nospamwrote :
      Hi
      >
      I have a class that I use in Excel to define some custom functions.
      The problem that I have is that the class also has some building
      functions
      that for some reason is there:
      ToString
      GetType
      GetHashCode
      Equals
      >
      They show up inside Excel and that is not good since my customers has no
      need for them.
      I have tryed to hide them using code like:
      private new string ToString()
      >
      {
      >
      return "";
      >
      }
      >
      But that has no effect.
      >
      The class is defined as:
      >
      [ClassInterface( ClassInterfaceT ype.AutoDual)]
      >
      public class Functions
      >
      Can anyone show me how to hide these buildin functions?
      >
      Thanks Torben
      >
      >
      >
      >


      --
      Happy Coding!
      Morten Wennevik [C# MVP]

      Comment

      • Torben Laursen

        #4
        Re: Hiding functions like ToString

        Thanks for the feedback

        Morten could you give me some feedback on how to rewrite the Excel class to
        I can hide these functions.
        I understand that they are important to .Net, but my users have no need for
        them inside Excel so they just "pollute" my interface

        I don't inhert the class from anything so the compiler(or Excel 2003) adds
        these functions to my class

        Torben

        "Morten Wennevik [C# MVP]" <MortenWennevik @hotmail.comwro te in message
        news:op.tmlqcif 8dj93y5@tr024.b ouvet.no...
        Hi Torben,
        >
        I may be wrong on this, but I would find it odd if you could hide these
        methods as they are essential to .Net and are defined in System.Object. I
        think you need to rewrite the Excel class to ignore those names.
        >
        >
        On Tue, 23 Jan 2007 10:51:31 +0100, Torben Laursen
        <Torben@newsgro ups.nospamwrote :
        >
        >Hi
        >>
        >I have a class that I use in Excel to define some custom functions.
        >The problem that I have is that the class also has some building
        >functions
        >that for some reason is there:
        >ToString
        >GetType
        >GetHashCode
        >Equals
        >>
        >They show up inside Excel and that is not good since my customers has no
        >need for them.
        >I have tryed to hide them using code like:
        >private new string ToString()
        >>
        >{
        >>
        >return "";
        >>
        >}
        >>
        >But that has no effect.
        >>
        >The class is defined as:
        >>
        >[ClassInterface( ClassInterfaceT ype.AutoDual)]
        >>
        >public class Functions
        >>
        >Can anyone show me how to hide these buildin functions?
        >>
        >Thanks Torben
        >>
        >>
        >>
        >>
        >
        >
        >
        --
        Happy Coding!
        Morten Wennevik [C# MVP]

        Comment

        • PhilipDaniels@foo.com

          #5
          Re: Hiding functions like ToString

          On Tue, 23 Jan 2007 11:20:03 +0100, "Torben Laursen"
          <Torben@newsgro ups.nospamwrote :
          >Thanks for the feedback
          >
          >Morten could you give me some feedback on how to rewrite the Excel class to
          >I can hide these functions.
          >I understand that they are important to .Net, but my users have no need for
          >them inside Excel so they just "pollute" my interface
          >
          >I don't inhert the class from anything so the compiler(or Excel 2003) adds
          >these functions to my class
          >
          >Torben
          snip<
          Please don't toppost!


          It can be done, you need to take control of how the COM interface is
          constructed on your class. Have to post quickly now because I have to
          go into a meeting but this is how it can be done. (Use Tools -Create
          GUID to make your own guids).

          First define an interface like this:

          [ComVisible(true )]
          [Guid("C63154DB-EB3E-4439-A9E4-015215BE116C")]
          [InterfaceType(C omInterfaceType .InterfaceIsIDi spatch)]
          public interface MyInterface {
          // your methods here
          }

          Then implement that interface on your class:

          [Guid("DD364688-B80D-4bfc-A167-B01F2F03F68D")]
          [ClassInterface( ClassInterfaceT ype.None)]
          [ProgId("MyServe r.MyClass")]
          [ComVisible(true )]
          public class MyClass: MyInterface {
          // implementations of your methods
          }


          Note the ClassInterfaceT ype.None attribute. If you do this, what you
          end up with is nice intellisense inside Excel which just shows the
          methods you defined in MyInterface.

          I blagged this off a webpage somewhere but can't for the life of me
          find it now. However, if you do a google search on
          ClassInterface( ClassInterfaceT ype.None) etc you will find plenty of
          examples and explanations of what this is actually doing.


          --
          Philip Daniels

          Comment

          • Otis Mukinfus

            #6
            Re: Hiding functions like ToString

            On Tue, 23 Jan 2007 11:20:03 +0100, "Torben Laursen" <Torben@newsgro ups.nospam>
            wrote:

            Inline:
            >Thanks for the feedback
            >
            >Morten could you give me some feedback on how to rewrite the Excel class to
            >I can hide these functions.
            >I understand that they are important to .Net, but my users have no need for
            >them inside Excel so they just "pollute" my interface
            >
            >I don't inhert the class from anything so the compiler(or Excel 2003) adds
            >these functions to my class
            The compiler does not "add" these methods to your class. They are part of every
            object (class) you define in .NET. And indeed you do inherit them, because
            every object in .NET inherits from the object base class.
            >
            >Torben
            >
            >"Morten Wennevik [C# MVP]" <MortenWennevik @hotmail.comwro te in message
            >news:op.tmlqci f8dj93y5@tr024. bouvet.no...
            >Hi Torben,
            >>
            >I may be wrong on this, but I would find it odd if you could hide these
            >methods as they are essential to .Net and are defined in System.Object. I
            >think you need to rewrite the Excel class to ignore those names.
            >>
            >>
            >On Tue, 23 Jan 2007 10:51:31 +0100, Torben Laursen
            ><Torben@newsgr oups.nospamwrot e:
            >>
            >>Hi
            >>>
            >>I have a class that I use in Excel to define some custom functions.
            >>The problem that I have is that the class also has some building
            >>functions
            >>that for some reason is there:
            >>ToString
            >>GetType
            >>GetHashCode
            >>Equals
            >>>
            >>They show up inside Excel and that is not good since my customers has no
            >>need for them.
            >>I have tryed to hide them using code like:
            >>private new string ToString()
            >>>
            >>{
            >>>
            >>return "";
            >>>
            >>}
            >>>
            >>But that has no effect.
            >>>
            >>The class is defined as:
            >>>
            >>[ClassInterface( ClassInterfaceT ype.AutoDual)]
            >>>
            >>public class Functions
            >>>
            >>Can anyone show me how to hide these buildin functions?
            >>>
            >>Thanks Torben
            >>>
            >>>
            >>>
            >>>
            >>
            >>
            >>
            >--
            >Happy Coding!
            >Morten Wennevik [C# MVP]
            >
            Good luck with your project,

            Otis Mukinfus


            Comment

            • Ignacio Machin \( .NET/ C# MVP \)

              #7
              Re: Hiding functions like ToString

              Hi,

              "Torben Laursen" <Torben@newsgro ups.nospamwrote in message
              news:eE1$PgtPHH A.140@TK2MSFTNG P04.phx.gbl...
              | Thanks for the feedback
              |
              | Morten could you give me some feedback on how to rewrite the Excel class
              to
              | I can hide these functions.
              | I understand that they are important to .Net, but my users have no need
              for
              | them inside Excel so they just "pollute" my interface



              | I don't inhert the class from anything so the compiler(or Excel 2003) adds
              | these functions to my class

              You have a missconception, ALL types inherit from Object. AS this is a
              constant you can avoid having to write it all the time.


              --
              Ignacio Machin
              machin AT laceupsolutions com


              Comment

              • Michael D. Ober

                #8
                Re: Hiding functions like ToString

                With the exception of the properties and methods of the Object class, you
                can hide _ALL_ inheritable properties and methods. Here's how (sample is in
                VB 2005 as I'm more familiar with it's class construction):

                // derived object shows inherited interfaces
                public class myClass
                inherits baseclass
                public sub New()
                mybase.new()
                end sub

                end class


                // "derived" class doesn't show inherited interfaces
                public class myClass
                {
                private base as baseclass

                public sub New()
                base = new baseclass
                end sub

                end class.

                In your case with Excel, you are better off with the second method and then
                also add a "quit" method that properly closes excel.

                Mike Ober.


                "Ignacio Machin ( .NET/ C# MVP )" <machin TA laceupsolutions .comwrote in
                message news:uo2u$BwPHH A.1380@TK2MSFTN GP05.phx.gbl...
                Hi,
                >
                "Torben Laursen" <Torben@newsgro ups.nospamwrote in message
                news:eE1$PgtPHH A.140@TK2MSFTNG P04.phx.gbl...
                | Thanks for the feedback
                |
                | Morten could you give me some feedback on how to rewrite the Excel class
                to
                | I can hide these functions.
                | I understand that they are important to .Net, but my users have no need
                for
                | them inside Excel so they just "pollute" my interface
                >
                >
                >
                | I don't inhert the class from anything so the compiler(or Excel 2003)
                adds
                | these functions to my class
                >
                You have a missconception, ALL types inherit from Object. AS this is a
                constant you can avoid having to write it all the time.
                >
                >
                --
                Ignacio Machin
                machin AT laceupsolutions com
                >
                >

                Comment

                • Dave Sexton

                  #9
                  Re: Hiding functions like ToString

                  Hi Torben,
                  They show up inside Excel and that is not good since my customers has no
                  need for them.
                  How do you know they have no need for them?

                  --
                  Dave Sexton

                  http://www.codeplex.com/DocProject (Sandcastle in VS IDE)

                  "Torben Laursen" <Torben@newsgro ups.nospamwrote in message
                  news:ezl3TQtPHH A.4992@TK2MSFTN GP04.phx.gbl...
                  Hi
                  >
                  I have a class that I use in Excel to define some custom functions.
                  The problem that I have is that the class also has some building functions
                  that for some reason is there:
                  ToString
                  GetType
                  GetHashCode
                  Equals
                  >
                  They show up inside Excel and that is not good since my customers has no
                  need for them.
                  I have tryed to hide them using code like:
                  private new string ToString()
                  >
                  {
                  >
                  return "";
                  >
                  }
                  >
                  But that has no effect.
                  >
                  The class is defined as:
                  >
                  [ClassInterface( ClassInterfaceT ype.AutoDual)]
                  >
                  public class Functions
                  >
                  Can anyone show me how to hide these buildin functions?
                  >
                  Thanks Torben
                  >
                  >
                  >
                  >

                  Comment

                  • Jon Skeet [C# MVP]

                    #10
                    Re: Hiding functions like ToString

                    Michael D. Ober <obermd.@.alum. mit.edu.nospamw rote:
                    With the exception of the properties and methods of the Object class, you
                    can hide _ALL_ inheritable properties and methods. Here's how (sample is in
                    VB 2005 as I'm more familiar with it's class construction):
                    >
                    // derived object shows inherited interfaces
                    public class myClass
                    inherits baseclass
                    public sub New()
                    mybase.new()
                    end sub
                    >
                    end class
                    >
                    >
                    // "derived" class doesn't show inherited interfaces
                    public class myClass
                    {
                    private base as baseclass
                    <snip>

                    Well, that's not using inheritance at all - you're not *hiding* the
                    inherited interfaces, you're not inheriting them in the first place!
                    That also means you can't use myClass as an instance of baseclass.

                    (It also ignores the OP's problem as it's the members of the Object
                    class that he's worried about.)

                    --
                    Jon Skeet - <skeet@pobox.co m>
                    http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
                    If replying to the group, please do not mail me too

                    Comment

                    Working...