How to hide GetType() method from COM?

Posted by ticky on Stack Overflow See other posts from Stack Overflow or by ticky
Published on 2010-05-12T10:34:24Z Indexed on 2010/05/12 10:44 UTC
Read the original article Hit count: 400

Filed under:
|
|
|

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?

© Stack Overflow or respective owner

Related posts about com

Related posts about hide