1

I made an automation Add-In for Excel, and I made several functions (formulas).

I have a class which header looks like this (it is COM visible):

[ClassInterface(ClassInterfaceType.AutoDual)]
[ComVisible(true)]
public class Functions
{}

In a list of methods, I see:

 ToString(), Equals(), GetHashCode() and GetType() methods.

Since all methods of my class are COM visible, I should somehow hide those 4. I succeeded with 3 of them:

ToString(), Equals(), GetHashCode()

but GetType() cannot be overriden.

Here is what I did with 3 of them:

 [ComVisible(false)]
 public override string ToString()
 {
    return base.ToString();
 }

 [ComVisible(false)]
 public override bool Equals(object obj)
 {
   return base.Equals(obj);
 }

 [ComVisible(false)]
 public override int GetHashCode()
 {
   return base.GetHashCode();
 }

This doesn't work:

[ComVisible(false)]
public override Type GetType()
{
  return base.GetType();
}

Here is the error message in Visual Studio when compile:

..GetType()': cannot override inherited member 'object.GetType()' because it is not marked virtual, abstract, or override

So, what should I do to hide the GetType() method from COM?

Dirk Vollmar
  • 172,527
  • 53
  • 255
  • 316
ticky
  • 363
  • 2
  • 12

2 Answers2

0

I thought COM used Interfaces and hides the implementation, so i would go with that. There is no way to hide GetType as fas as i know.

Jouke van der Maas
  • 4,117
  • 2
  • 28
  • 35
0

You should introduce a new COM interface and inherit your class from it with ClassInterfaceType.None. This way you will only expose the methods in that interface.

Community
  • 1
  • 1
sharptooth
  • 167,383
  • 100
  • 513
  • 979
  • Both of you were right, guys! I implemented like you said - interface WITHOUT ToString() etc... Only methods that I needed. In my class, I've set: [ClassInterface(ClassInterfaceType.None)] [ComVisible(true)] public class Functions : IFunctions and I implemented methods from IFunctions. THANKS! – ticky May 12 '10 at 12:09