In C#, you can use Reflection to retrieve all the interfaces implemented by a given type. Here's an example:
main.cs449 chars23 lines
In this example, we define a class MyClass
that implements two interfaces: IDisposable
and ICloneable
. We then use the typeof
operator to get a Type
object representing MyClass
, and call the GetInterfaces
method on that object to get an array of Type
objects representing the interfaces implemented by MyClass
. We then simply loop through that array and print out the names of each interface.
This will output:
main.cs23 chars3 lines
gistlibby LogSnag