Where does ToString, GetHashCode & GetType come from??

F

Fredrik Wahlgren

Hi

I found an interesting piece of code which shows how to makee an Excel
automation add-in at http://www.codeproject.com/dotnet/excelnetauto.asp. I
decide to experiment with it and i made a few changes. I now have a method
that takes an Excel.Range as a parameter. My problem now is that when I use
Excel's function wizard, there are thre more functions available, namely
ToString, GetHashCode & GetType. I don't want them. How can I get rid of
them?

BTW. Can someone explain the difference between Range and IRange. The former
is a dispinterface while the latter is an interface in the idl file that i
have generated. In what scenarios do you use IRange?

TIA,
Fredrik

Here's my modified code.

using System;
using System.Runtime.InteropServices;
using Excel;
// using Excel = Microsoft.Office.Interop.Excel;


namespace NAddIn
{
[ClassInterface(ClassInterfaceType.AutoDual)]
public class Functions
{
public Functions()
{
}

public int GetRangeSize(Excel.Range range)
{
return range.Columns.Count * range.Rows.Count;
}

[ComRegisterFunctionAttribute]
public static void RegisterFunction(Type t)
{
Microsoft.Win32.Registry.ClassesRoot.CreateSubKey(
"CLSID\\{" + t.GUID.ToString().ToUpper() +
"}\\Programmable");
}

[ComUnregisterFunctionAttribute]
public static void UnregisterFunction(Type t)
{
Microsoft.Win32.Registry.ClassesRoot.DeleteSubKey(
"CLSID\\{" + t.GUID.ToString().ToUpper() +
"}\\Programmable");
}
}
}
 
F

Fredrik Wahlgren

Bob Grommes said:
Those methods are inherited from Object. Every .NET class has them.

--Bob


I don't think they appeared in the original project. They came when I added
a reference to Excel and cretaed my GetRangeSize function. I sthere anyway I
can hide them? They don't make much sense as worksheet functions, do they?
/Fredrik
 
M

Morten Wennevik

Hi Fredrik,

Everything in .Net inherits from Object, and Object has a few methods like
Equals, ToString, GetType and GetHashCode. They are necessary for .net to
work so you can't get rid of them. You may however override them to get a
more meaningful result.

For instance ToString will return a string of the type of the object, but
you can make it return anything you like, Int32 returns its integer value,
a DateTime its date and time, a String actually returns its string etc.
GetType will return the original type of an object which may be different
than the reference type currently used.
 

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