简体   繁体   English

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

[英]Type.GetInterfaces() workaround for .NET Standard 1.x

.NET Core 1.1 supports Type.GetInterfaces() method which provides a list of the interfaces implemented on a given type. .NET Core 1.1支持Type.GetInterfaces()方法,该方法提供在给定类型上实现的接口列表。 Unfortunately, Type.GetInterfaces() is not yet available in .NET Standard 1.x . 不幸的是, Type.GetInterfaces().NET Standard 1.x尚不可用。

The good news is that it is supposed to included in .NET Standard 2.0 . 好消息是它应该包含在.NET Standard 2.0

In the meantime, does anyone know of a workaround I can use to get the list of interfaces on a type and/or the list of classes which implement a given interface in .NET Standard 1.x ? 与此同时,有没有人知道我可以用来获取.NET Standard 1.x实现给定接口的类型和/或类列表上的接口列表的变通方法?

Many thanks! 非常感谢!

This should do the trick. 这应该可以解决问题。 GetTypeInfo() is an extension method in the System.Reflection namespace, part of the InstrospectionExtensions . GetTypeInfo()是在一个扩展方法System.Reflection命名空间,所述的一部分InstrospectionExtensions

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM