asp net 3.5unleashed

Page 491

class App { static void Main() { // Find the interfaces implemented by MyRetailer where // the interface is defined in your own assembly. This // is accomplished using a delegate to a filter method // that you create and pass to FindInterfaces. Type t = typeof(MyRetailer); Type[] interfaces = t.FindInterfaces( new TypeFilter(App.TypeFilter), Assembly.GetCallingAssembly().GetName()); Console.WriteLine("MyRetailer implements the following " + "interfaces (defined in this assembly):");

// Show information about each interface. foreach (Type i in interfaces) { Console.WriteLine("\nInterface: " + i);

// Get the type methods that map to the interface’s meth ods. InterfaceMapping map = t.GetInterfaceMap(i);

for (Int32 m = 0; m < map.InterfaceMethods.Length; m++) { // Display the interface method name and which type // method implements the interface method. Console.WriteLine("

{0} is implemented by {1}",

map.InterfaceMethods[m], map.TargetMethods[m]); } } }

// This filter delegate method takes a type and an object, per forms // some check, and returns true if the type is to be included // in the array of returned types. static Boolean TypeFilter(Type t, Object filterCriteria) { // Return true if the interface is defined in the same // assembly identified by filterCriteria. return t.Assembly.GetName().ToString() == filterCriteria.ToString(); }


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.