I would like to have my classes exposed without displaying the base methods Equals(), GetHashCode(), GetType(), ToString(). I also want Intellisense to work properly. Here is my sample code:
using System;
using System.IO;
using System.Runtime.InteropServices;
namespace InteropTest
{
[ClassInterface(ClassInterfaceType.AutoDual),
ComVisible(true)]
[ProgId("InteropTest.Wrapper")]
public class Wrapper
{
public string Text1 = "hello";
public string Text2 = "world";
public Class1 Class1 = new Class1();
public Class2 Class2 = new Class2();
}
[ClassInterface(ClassInterfaceType.AutoDual),
ComVisible(true)]
public class Class1
{
public string Method1a(string myText)
{
return myText;
}
public string Method1b(string myText)
{
return myText;
}
}
[ClassInterface(ClassInterfaceType.AutoDual),
ComVisible(true)]
public class Class2
{
public string Method2a(string myText)
{
return myText;
}
public string Method2b(string myText)
{
return myText;
}
}
}
When I use [ClassInterface(ClassInterfaceType.None), ComVisible(true)], I can see the 2 properties in the Wrapper class, but I cannot see, nor access, Class1 or Class2.
When I use this class, I expect to be able to create the object and use it.
o = CreateObject(“InteropTest.Wrapper”)
o.Class1.Method1a(“Some text”)
I guess, my real question is, how do I setup my classes for COM and make both Class1 and Class2 visible without displaying the extra methods?
I also tried using the refactor tool to extract the interfaces, but I could not get those to work the way I want to work, either. I don’t want to put in any funky work-arounds, either.