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);
}
 
Back
Top