Reflecting inherited interfaces

H

Hans Ruck

I'm trying to detect the interfaces directly inherited by a class. I've
tried to use the Type.GetInterfaces method but in a situation like
this:

public interface I
{
void f();
}

public interface I2 : I
{
void f2();
new void f();
}

public interface Ii : I, I2
{
new void f();
new void f2();
void f1();
}

public class CC : Ii
{
public void f(){}
public void f1(){}
public void f2(){}
}

the entire interface types' hierarchy would be returned as a list ( Ii
and I instead of Ii ).

Is there any way to detect the relationship between two parent-child
interfaces? Or: is it possible to obtain only the interfaces directly
inherited by a class?
 
M

Mattias Sjögren

Is there any way to detect the relationship between two parent-child
interfaces?

Sure. typeof(Ii).GetInterfaces() should return an array containing
typeof(I) and typeof(I2) for example.

Or: is it possible to obtain only the interfaces directly
inherited by a class?

No, if you look at the compiled code in Ildasm.exe you'll see that the
class actually explicitly implements all three interfaces.


Mattias
 

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