Question about interfaces

  • Thread starter Thread starter Geoff Pennington
  • Start date Start date
G

Geoff Pennington

Is there an easy way to find out what classes implement a given interface?
For example, it might be useful to know what classes implement ICollectible.

Much obliged,
Geoff.
 
If TypeOf myCollection Is ICollectible Then
' myCollection implements ICollectible
End If

If GetType(ICollectible).IsAssignableFrom(myCollection.GetType) Then
'again, myCollection implements ICollectible
End If

In C#, I believe you can use the typeof keyword to get the type of an
object.

Also, You can use the Type.GetInterfaces method to get a collection of type
objects for all the interfaces implemented by an object. You can also use
the Type.GetInterface method to get an interface by name.

hope that helps..
Imran.
 
Geoff Pennington said:
Is there an easy way to find out what classes implement a given interface?
For example, it might be useful to know what classes implement ICollectible.

Again, MSDN is your friend. Go to the overview page for the interface,
and it lists the classes which implement it directly.
 
If I understand correctly, you are answering the opposite question from the
one I asked. Your reply seems to address the question "What interfaces does
this class implement?", but what I want to know is "What classes implement
this interface?".

Sometimes, when choosing a class for a specific purpose, I want to be sure I
have considered all the options.

Geoff.
 
OK, good. Thanks.

Jon Skeet said:
ICollectible.

Again, MSDN is your friend. Go to the overview page for the interface,
and it lists the classes which implement it directly.
 
Geoff Pennington said:
If I understand correctly, you are answering the opposite question from the
one I asked. Your reply seems to address the question "What interfaces does
this class implement?", but what I want to know is "What classes implement
this interface?".

My apologies. I misread your question. However, there's no way through code
to figure out what classes implement a given interface. If you are talking
about classes and interfaces in the .NET class library, you can look up the
MSDN documentation for the given interface - it'll have a list of classes
that directly implement the interface.

hope that helps..
Imran.
 
Back
Top