Telling if a class implements a specific interface

  • Thread starter Thread starter Brian Henry
  • Start date Start date
B

Brian Henry

Is there any way to tell if a class implements a specific interface such as
IComparable for example? thanks
 
* "Brian Henry said:
Is there any way to tell if a class implements a specific interface such as
IComparable for example? thanks

If you have an instance of the class:

\\\
If TypeOf foo Is IComparable Then
...
End If
///

If you don't have an instance, 'GetType(Foo).GetInterface(...)'.
 
Yes - you can do that using reflection.

look at the GetInterfaces method of the 'Type' class. It will return an
array of 'Type' objects representing all the interfaces either implement or
inherited by a given type.

hope this helps..
Imran.
 
thanks a lot

Imran Koradia said:
Yes - you can do that using reflection.

look at the GetInterfaces method of the 'Type' class. It will return an
array of 'Type' objects representing all the interfaces either implement
or
inherited by a given type.

hope this helps..
Imran.
 
Brian,
To check for a specific interface you can use:

GetType(IComparable).IsAssignableFrom(GetType(SomeClass))

Hope this helps
Jay
 

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