3

Can someone tell me how to find all interfaces that a class implements by using C# reflection ?

Like find all classes that implement a specific interface

if(type.getInterface(typeof(IAuto)) != null)
{
   console.writeline(type.name.tostring());
}
bknopper
  • 1,193
  • 12
  • 28
  • possible duplicate of [Getting all types that implement an interface with C# 3.0](http://stackoverflow.com/questions/26733/getting-all-types-that-implement-an-interface-with-c-sharp-3-0) – Seany84 Mar 04 '14 at 11:00
  • It's not a duplicate. It's vice versa. It's more like: http://stackoverflow.com/questions/2055411/find-the-immediate-implemented-interfaces-on-a-type – Scoregraphic Mar 04 '14 at 11:02
  • 1
    @Scoregraphic I thought that too, until I saw the example. The title says something different than the example shows. OP, can you clarify? In description: *find all class that implements specific interface* is the opposite of title: *Finding all Interface that a class implements* – CodingIntrigue Mar 04 '14 at 11:02
  • i want to know Finding all Interface that a class implements .... –  Mar 04 '14 at 11:20

1 Answers1

8
var interfaces = typeof(Classname).GetInterfaces();
Flat Eric
  • 7,971
  • 9
  • 36
  • 45