鉴于此:
Interface IBase {string X {get;set;}}
Interface ISuper {string Y {get;set;}}
class Base : IBase {etc...}
class Super : Base, ISuper {etc...}
void Questionable (Base b) {
Console.WriteLine ("The class supports the following interfaces... ")
// The Magic Happens Here
}
我可以用什么替换“The Magic”来显示对象 b 上支持的接口(interface)?
是的,我知道它属于 Base 类,它支持“IBase”,真正的层次结构比这个更复杂。 :)
谢谢! -DF5
编辑:既然我已经看到了答案,我会因为没有通过 Intellisense 被它绊倒而感到愚蠢。 :)
谢谢大家! -DF5
最佳答案
魔法:
foreach (Type iface in b.GetType().GetInterfaces())
Console.WriteLine(iface.Name);
关于c# - 给定一个对象,我如何以编程方式告诉它支持哪些接口(interface)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/395549/