Hiding functions like ToString

T

Torben Laursen

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
 
J

Jacob

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

Morten Wennevik [C# MVP]

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.


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
 
T

Torben Laursen

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 said:
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.


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
 
P

PhilipDaniels

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

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.InterfaceIsIDispatch)]
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.
 
O

Otis Mukinfus

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 said:
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.


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
Good luck with your project,

Otis Mukinfus
http://www.arltex.com
http://www.tomchilders.com
 
I

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

Hi,

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

Michael D. Ober

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

Dave Sexton

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 said:
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
 
J

Jon Skeet [C# MVP]

Michael D. Ober said:
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.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top