#453 – Use Reflection to Get a List of Interfaces that a Class Implements
November 11, 2011 Leave a comment
You can query an object at runtime, using reflection, to get information about its members. This includes the interfaces that the object’s class implements.
Cow bessie = new Cow("Bessie", 4); // Use reflection to dump out information about // Bessie's interfaces and the methods in // each interface. Type t = bessie.GetType(); foreach (Type iType in t.GetInterfaces()) { Console.WriteLine("Interface [{0}]:", iType.Name); foreach (MemberInfo minfo in iType.GetMembers()) { Console.WriteLine(" {0}", minfo.Name); } }