Reflecting on Implemented Interfaces
Next, you will author a method named ListInterfaces() that will print out the names of any
interfaces supported on the incoming type. The only point of interest here is that the call to
GetInterfaces() returns an array of System.Types! This should make sense given that interfaces
are, indeed, types:
// Display implemented interfaces.
static void ListInterfaces(Type t)
{
Console.WriteLine("***** Interfaces *****");
Type[] ifaces = t.GetInterfaces();
foreach(Type i in ifaces)
Console.WriteLine("->{0}", i.Name);
}
C H A P T E R 1 6
■
T Y P E R E F L E C T I O N, L AT E B I N D I N G, A N D AT T R I B U T E - B A S E D P R O G R A M M I N G
531
8849CH16.qxd 10/9/07 4:27 PM Page 531
Do'stlaringiz bilan baham: |