鉴于这种:
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 }
有什么可以替换"魔术"来显示对象b上支持的接口?
是的,我知道作为类Base它支持"IBase",真正的层次结构更加复杂.:)
谢谢!-DF5
编辑:现在我已经看到了答案,我感到愚蠢的是没有通过Intellisense绊倒它.:)
谢谢大家!-DF5
b.GetType().GetInterfaces()
魔法 :
foreach (Type iface in b.GetType().GetInterfaces()) Console.WriteLine(iface.Name);