Interface inheritance with COM


G

Guest

I'm trying to implement two classes, one derived from the other, each of
which is based on an interface and make the whole thing visible to COM.
Here's what I have

public interface IMyBase
{
int Property1 { get; }
void Method1(int n);
}

[ClassInterface(ClassInterfaceType.None)]
public class MyBase : IMyBase
{
public int Property1 { get { /*implementation*/ } }
public void Method1(int n) { /*implementation*/ }
}

public interface IMyDerived : IMyBase
{
void Method2(int n);
}

[ClassInterface(ClassInterfaceType.None)]
public class MyDerived : IMyDerived
{
public void Method2(int n) { /*implementation*/ }
}

When I try to use this from a VB6 client, I can see MyBase properly. I can
also see MyDerived, but only 'Method2'. I cannot see the 'MyBase'
methods/properties from the MyDerived interface. I've tried a few variations
on the declaration of the MyDerived class, including:
public class MyDerived : MyBase, IMyDerived
to no avail.

Does anyone have any ideas how I can make the base interface
methods/properties available through the derived interface?

Thanks.
 
Ad

Advertisements

M

Mattias Sjögren

Does anyone have any ideas how I can make the base interface
methods/properties available through the derived interface?

Try it like this

public interface IMyDerived : IMyBase
{
new int Property1 { get; }
new void Method1(int n);
void Method2(int n);
}


Mattias
 
Ad

Advertisements

G

Guest

Thanks for the response. That works but it seems a bit clumsy. If I have a
few interfaces derived from the base then I have to duplicate the base
method/property declarations in all the derived ones?? There ought to be a
better way...

Ken
 

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