gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 20:12:41 25 4
gpt4 key购买 nike

.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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com