How to get interface basetype via reflection?

前端 未结 3 1792
孤街浪徒
孤街浪徒 2020-12-05 14:01
public interface IBar {} 
public interface IFoo : IBar {}

typeof(IFoo).BaseType == null

How can I get IBar?

3条回答
  •  眼角桃花
    2020-12-05 14:36

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

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

    Type type = typeof(IFoo).GetInterface("IBar");
    

提交回复
热议问题