如何通过反射获取接口基本类型? [英] How to get interface basetype via reflection?

查看:161
本文介绍了如何通过反射获取接口基本类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 公共接口伊巴尔{}
公共接口的IFoo:伊巴尔{}typeof运算(的IFoo).BaseType == NULL

我怎样才能得到伊巴尔?


解决方案

 键入[]类型= ty​​peof运算(的IFoo).GetInterfaces();

编辑:如果你特别希望伊巴尔,你可以这样做:

 键入类型= ty​​peof运算(的IFoo).GetInterface(IBAR);

public interface IBar {} 
public interface IFoo : IBar {}

typeof(IFoo).BaseType == null

How can I get IBar?

解决方案

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

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

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

这篇关于如何通过反射获取接口基本类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆