public interface IBar {} public interface IFoo : IBar {} typeof(IFoo).BaseType == null
How can I get IBar?
GetInterface(String) Method This method is used to search for the interface with the specified name. Syntax: public Type GetInterface (string name); Here, it takes the string containing the name of the interface to get. For generic interfaces, this is the mangled name.
An interface defines a contract. Any class or struct that implements that contract must provide an implementation of the members defined in the interface. An interface may define a default implementation for members. It may also define static members in order to provide a single implementation for common functionality.
The base type is the type from which the current type directly inherits. Object is the only type that does not have a base type, therefore null is returned as the base type of Object.
A base class, in the context of C#, is a class that is used to create, or derive, other classes. Classes derived from a base class are called child classes, subclasses or derived classes. A base class does not inherit from any other class and is considered parent of a derived class.
Type[] types = typeof(IFoo).GetInterfaces();
Edit: If you specifically want IBar, you can do:
Type type = typeof(IFoo).GetInterface("IBar");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With