The GetInterfaces() method

  • Thread starter Thread starter Abdessamad Belangour
  • Start date Start date
A

Abdessamad Belangour

Hi all,
the GetInterfaces() method of the Type class, brings all the interfaces
implemented by a Class. The problem is that the method brings also all the
interfaces implemented by it base type. Is there any flag to block the
inherited interfaces ?
thanks again.
 
Abdessamad Belangour said:
the GetInterfaces() method of the Type class, brings all the interfaces
implemented by a Class. The problem is that the method brings also all the
interfaces implemented by it base type. Is there any flag to block the
inherited interfaces ?

Not that I know of (I suspect it's not a requirement that's
particularly common) - the easiest thing to do would be to call
GetInterfaces on both the type and its base type, and then remove
anything in the latter set from the former set. Something like:

Type[] allInterfaces = type.GetInterfaces();
// I'll assume for the moment that type != typeof(object)
Type[] baseInterfaces = type.BaseType.GetInterfaces();

ArrayList list = new ArrayList();
list.AddRange(allInterfaces);
foreach (Type t in baseInterfaces)
{
list.Remove (t);
}
 

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