C#: Determining whether a class implements certain interface

typeof(IMyInterface).IsAssignableFrom(myClassInstance.GetType());
typeof(IMyInterface).IsAssignableFrom(typeof(MyClass));

Type.IsAssignableFrom()

Return Value
Type: System.Boolean

true if c and the current Type represent the same type, or if the current Type is in the inheritance hierarchy of c, or if the current Type is an interface that c implements, or if c is a generic type parameter and the current Type represents one of the constraints of c. false if none of these conditions are true, or if c is a null reference.

circle’s Notes: C#: Determining whether a class implements certain interface

Author: admin