Reflection--can I determine if an interface was inherited without checking the base class?

  • Thread starter Thread starter Jeff Johnson [MVP: VB]
  • Start date Start date
J

Jeff Johnson [MVP: VB]

As a learning experience, I'm writing my own object browser. I want to make
it work very similar to the object browser in the VS IDE, and to that end I
only want to display interfaces under the type in which they are declared.
However, the Type class doesn't have an IsInherited property nor any other
property or method that jumps out at me as providing this information. It
would be nice if the GetInterfaces() method were overloaded to provide all
interfaces or only those declared by the type.

I know that I could dig down into the base class and see if it too has that
interface and thus not show it under the subclass, but I was trying to be
super efficient and only populate nodes one branch at a time. This dig-down
approach would of course violate that pattern. Unfortunately, at the moment
that appears to be the only solution. Any suggestions?
 
Jeff,
It
would be nice if the GetInterfaces() method were overloaded to provide all
interfaces or only those declared by the type.

Totally agree, this is currently an annoying missing feature in the
Reflection library.

I know that I could dig down into the base class and see if it too has that
interface and thus not show it under the subclass

Even that might not be correct, since some languages (such as C#) let
subclasses re-implement an interface. So you can have

class Base : IFoo {}
class Derived : Base, IFoo {}

and in this case the correct thing would be to show IFoo implemented
in both Base and Derived.



Mattias
 
Back
Top