question on inheritance of interfaces..

  • Thread starter Thread starter parez
  • Start date Start date
P

parez

I have interface IAbc,IDef

and interface IXyz inherits/implements(what is the right word) IAbc
and IDef


if i reflect the type IXyz it only shows me the members of IXyz and
not IAbc and IDef.

Why?

TIA
 
  I have interface IAbc,IDef

and  interface  IXyz inherits/implements(what is the right word) IAbc
and IDef

 if  i  reflect the type IXyz it only shows me the members of IXyz and
not IAbc and IDef.

Why?

TIA

Let me see if I understand this:
You have an interface named IXYZ that implements IABC and IDef

public interface IABC
{
void MethodFromABC();
}

public interface IDef
{
void MethodFromIDef();
}

public inteface IXYZ : IDef, IABC
{
void MethodFromIXYZ();
}

Running reflection against IXY only returns MethodFromIXYZ()?

Is that correct?
 
Let me see if I understand this:
You have an interface named IXYZ that implements IABC and IDef

public interface IABC
{
void MethodFromABC();

}

public interface IDef
{
void MethodFromIDef();

}

public inteface IXYZ : IDef, IABC
{
void MethodFromIXYZ();

}

Running reflection against IXY only returns MethodFromIXYZ()?

Is that correct?

Correct...
 
parez said:
I have interface IAbc,IDef

and interface IXyz inherits/implements(what is the right word) IAbc
and IDef


if i reflect the type IXyz it only shows me the members of IXyz and
not IAbc and IDef.

Why?

Because you didn't use BindingFlags.FlattenHierarchy
 
parez said:
can you please shed some more light on it..


Actually, it looks like BindingFlags.FlattenHierarchy is only needed for
static members (which interfaces don't have), sorry about that.
Type.GetMethods specifically guarantees that non-static members of a base
class are returned, but doesn't mention interfaces. You can always iterate
though the interfaces returned by Type.GetInterfaces, though, to find the
interface members.
 
can you please shed some more light on it..- Hide quoted text -

- Show quoted text -

I don't think FlattenHierarchy works with interfaces. Found this on
the MSDN boards:

ShowInterfaceMethods(typeof(myInterface));

ShowInterfaceMethods(Type iType)
{


foreach (MethodInfo mi in
iType.GetMethods(BindingFlags.Public | BindingFlags.Instance |
BindingFlags.FlattenHierarchy))
{

Console.Writeline(mi.Name);
}

foreach (Type IBase in iType.GetInterfaces())
{

GetInterfaceMethods(IBase);

}

}
 
can you please shed some more light on it..

Thanks both.. .I got what i wanted..

But is there a reason why I have to do that? Is it an oversight on ms
side?
 

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

Back
Top