473,224 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,224 software developers and data experts.

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 4147
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Lorenzo Villari | last post by:
I premise I don't know C++ well but... I wondered what is this data hiding thing... I mean, if I can look at the header (and i need it beacuse of the class), then what's hidden? Can someone give...
17
by: Bob Weiner | last post by:
What is the purpose of hiding intead of overriding a method? I have googled the question but haven't found anything that makes any sense of it. In the code below, the only difference is that...
2
by: News | last post by:
Hi, I need help with datalist and linkbutton. I need a LinkButton to display in datalist if datafield "is_measure_customchecklist" in a db table set to true. Here is the code (in parts): ...
9
by: bob | last post by:
Hi, I know there exists a good reason why the designers of c++ decided that function hiding should exist. But I don't know why. Can anybody provide a good reason/example of a case where function...
2
by: subramanian100in | last post by:
Is my following understanding correct ? Data abstraction means providing the interface - that is, the set of functions that can be called by the user of a class. Information hiding means...
2
by: developer.new | last post by:
Hi I have a question regarding this concept I learned about recently: Name Hiding. Here's what I've come across: There is a base class with two functions with the same name but different...
13
by: mattia | last post by:
Hi everybody, I'm wondering how to realize a simple pattern in C: information hiding, to hide detail implementations of a data structure. How can I do that? I've also read that is preferred to use...
162
by: Sh4wn | last post by:
Hi, first, python is one of my fav languages, and i'll definitely keep developing with it. But, there's 1 one thing what I -really- miss: data hiding. I know member vars are private when you...
27
by: matt | last post by:
Hello group, I'm trying to become familiar with the information hiding design rules, and I have a lot (3) of questions for all you experts. AFAIK, a generic module has 2 files: ...
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.