473,396 Members | 1,766 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,396 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 4159
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: ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.