This question already has answers here:
How to find out which interfaces a .net class implements?
(4 个回答)
3年前关闭。
有没有办法在 Visual Studio UI 中获取 C# 类的所有接口(interface)的列表,而无需一步一步地挖掘父类(super class)链?如果甚至 MSDN 上的列表都没有用处。
例如,如果不深入研究
(4 个回答)
3年前关闭。
有没有办法在 Visual Studio UI 中获取 C# 类的所有接口(interface)的列表,而无需一步一步地挖掘父类(super class)链?如果甚至 MSDN 上的列表都没有用处。
例如,如果不深入研究
Form
,我就看不到 IDisposable
是 Control
。 最佳答案
获取接口(interface):typeof(List<string>).GetInterfaces()
返回Type[] (8 items)4typeof(IList<String>)typeof(ICollection<String>)typeof(IEnumerable<String>)typeof(IEnumerable)typeof(IList)typeof(ICollection)typeof(IReadOnlyList<String>)typeof(IReadOnlyCollection<String>)
如果需要了解特定接口(interface),可以使用 IsAssignableFrom:typeof(ICollection).IsAssignableFrom(typeof(List<string>))
返回 true
关于c# - 在 Visual Studio 中获取 C# 类的所有接口(interface),我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49868345/
10-13 08:05