views:

136

answers:

2

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?

A: 

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
A: 

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.

sharptooth
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 : IFunctionsand I implemented methods from IFunctions.THANKS!
ticky