c# - .NET Standard 1.x 的 Type.GetInterfaces() 解决方法

标签 c# reflection .net-core asp.net-core-1.0 .net-standard

.NET Core 1.1 支持 Type.GetInterfaces() 方法,该方法提供在给定类型上实现的接口(interface)列表。遗憾的是,Type.GetInterfaces().NET Standard 1.x 中尚不可用。

好消息是它应该包含在 .NET Standard 2.0 中。

与此同时,有没有人知道我可以用来获取类型的接口(interface)列表和/或在 .NET Standard 1.x 中实现给定接口(interface)的类列表的变通方法>?

非常感谢!

最佳答案

这应该可以解决问题。 GetTypeInfo()System.Reflection 命名空间中的扩展方法,是 InstrospectionExtensions 的一部分。

using System.Reflection;
var interfaces = typeof({SOME_TYPE}).GetTypeInfo().GetInterfaces();

关于c# - .NET Standard 1.x 的 Type.GetInterfaces() 解决方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44191048/

相关文章:

c# - 如何从列表中删除冗余顶点

c# - 如何使用 System.Lazy 和 Setter 来延迟初始化 POCO 实体中的列表?

java - 我可以获得 Resteasy 使用的 ResourceMethodRegistry

oracle - SQLAlchemy MetaData.reflect 在 Oracle 数据库中找不到表

c# - 导出所有 specflow 步骤定义以制作测试教程

c# - Windows Mobile 项目中的 System.Reflection

java - GWTTestCase:测试私有(private)方法

c# - .NET Core Main() 中的依赖注入(inject)不起作用

c# - ToListAsync 抛出 'Value cannot be null.' 异常

c# - 使用 CancellationToken 打破循环