Get assembly interface implementations

G

Guest

Is there a way to get the names of all classes that implements a certain
interface from an assembly?
 
S

Stoitcho Goutsev \(100\)

Joachim,

There is no direct method, but it is still pretty straightgforward to
implement.

Assembly.GetTypes return array of Type object for types declared in the
assembly. Once you have this array you need to filter out all types that
implement that inteface. To do that you can go throught all Type objects in
the array and using one of the fillowing methods:

Type.GetInterface("<interface name>") and check the return value against
*null*

or

typeof(<interface name>).IsAssignableFrom(<type object from the
collection>) - In this case *true* indicates that the type represented by
Type object from the array implements specified interface.
 

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

Top