Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get interface basetype via reflection?

public interface IBar {}  public interface IFoo : IBar {}  typeof(IFoo).BaseType == null 

How can I get IBar?

like image 629
Kevin Driedger Avatar asked Feb 11 '09 20:02

Kevin Driedger


People also ask

How do I find the interface type?

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.

What does an interface Do C#?

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.

What is the base Type?

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.

What is base Type class in c#?

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.


1 Answers

Type[] types = typeof(IFoo).GetInterfaces(); 

Edit: If you specifically want IBar, you can do:

Type type = typeof(IFoo).GetInterface("IBar"); 
like image 113
BFree Avatar answered Oct 04 '22 22:10

BFree