470,831 Members | 1,689 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,831 developers. It's quick & easy.

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(ClassInterfaceType.AutoDual)]

public class Functions

Can anyone show me how to hide these buildin functions?

Thanks Torben


Jan 23 '07 #1
9 4011
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(ClassInterfaceType.AutoDual)]

public class Functions

Can anyone show me how to hide these buildin functions?

Thanks Torben
Jan 23 '07 #2
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
<To****@newsgroups.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(ClassInterfaceType.AutoDual)]

public class Functions

Can anyone show me how to hide these buildin functions?

Thanks Torben



--
Happy Coding!
Morten Wennevik [C# MVP]
Jan 23 '07 #3
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]" <Mo************@hotmail.comwrote in message
news:op***************@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
<To****@newsgroups.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(ClassInterfaceType.AutoDual)]

public class Functions

Can anyone show me how to hide these buildin functions?

Thanks Torben


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

Jan 23 '07 #4
On Tue, 23 Jan 2007 11:20:03 +0100, "Torben Laursen"
<To****@newsgroups.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(ComInterfaceType.InterfaceIsIDispatc h)]
public interface MyInterface {
// your methods here
}

Then implement that interface on your class:

[Guid("DD364688-B80D-4bfc-A167-B01F2F03F68D")]
[ClassInterface(ClassInterfaceType.None)]
[ProgId("MyServer.MyClass")]
[ComVisible(true)]
public class MyClass: MyInterface {
// implementations of your methods
}
Note the ClassInterfaceType.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(ClassInterfaceType.None) etc you will find plenty of
examples and explanations of what this is actually doing.
--
Philip Daniels
Jan 23 '07 #5
On Tue, 23 Jan 2007 11:20:03 +0100, "Torben Laursen" <To****@newsgroups.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]" <Mo************@hotmail.comwrote in message
news:op***************@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
<To****@newsgroups.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(ClassInterfaceType.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
http://www.arltex.com
http://www.tomchilders.com
Jan 23 '07 #6
Hi,

"Torben Laursen" <To****@newsgroups.nospamwrote in message
news:eE*************@TK2MSFTNGP04.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
Jan 23 '07 #7
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:uo**************@TK2MSFTNGP05.phx.gbl...
Hi,

"Torben Laursen" <To****@newsgroups.nospamwrote in message
news:eE*************@TK2MSFTNGP04.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


Jan 23 '07 #8
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://davesexton.com/blog
http://www.codeplex.com/DocProject (Sandcastle in VS IDE)

"Torben Laursen" <To****@newsgroups.nospamwrote in message
news:ez**************@TK2MSFTNGP04.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(ClassInterfaceType.AutoDual)]

public class Functions

Can anyone show me how to hide these buildin functions?

Thanks Torben


Jan 23 '07 #9
Michael D. Ober <obermd.@.alum.mit.edu.nospamwrote:
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 - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 23 '07 #10

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Lorenzo Villari | last post: by
17 posts views Thread by Bob Weiner | last post: by
9 posts views Thread by bob | last post: by
2 posts views Thread by developer.new | last post: by
13 posts views Thread by mattia | last post: by
27 posts views Thread by matt | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.