适用于.NET Standard 1.x的Type.GetInterfaces()变通方法

Ant*_*lin 7 c# reflection .net-core asp.net-core-1.0 .net-standard

.NET Core 1.1支持Type.GetInterfaces()方法,该方法提供在给定类型上实现的接口列表.不幸的是,Type.GetInterfaces()还没有.NET Standard 1.x.

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

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

非常感谢!

Rob*_*dez 9

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

using System.Reflection;
var interfaces = typeof({SOME_TYPE}).GetTypeInfo().GetInterfaces();
Run Code Online (Sandbox Code Playgroud)