3 // Nick Drochak (ndrochak@gol.com)
\r
5 // (C) 2001 Nick Drochak
\r
8 using System.Reflection;
\r
9 using System.Collections;
\r
15 public static void Main(string[] args) {
\r
18 InterfaceMapping map;
\r
20 ArrayList TypesList = new ArrayList();
\r
21 ArrayList implementingTypes = new ArrayList();
\r
22 string asmFullPath = null;
\r
23 string ifaceToDiscover = null;
\r
25 if (args.Length < 1 || args.Length > 3) {
\r
30 for (int i = 0; i < args.Length; i++) {
\r
31 string arg = args[i];
\r
33 if (arg.StartsWith("-") && ((i + 1) < args.Length)) {
\r
34 if (arg == "--asm") {
\r
35 asmFullPath = args[++i];
\r
41 // allow only one interface to discover
\r
42 if (ifaceToDiscover != null){
\r
46 ifaceToDiscover = arg;
\r
50 // find the assembly
\r
51 if (null == asmFullPath){
\r
52 asm = Assembly.GetAssembly(typeof (System.Object));
\r
56 asm = Assembly.LoadFrom(asmFullPath);
\r
59 Console.WriteLine("Could not open assembly '{0}' for discovery. Error is: "+e.Message, asmFullPath);
\r
63 asmTypes = asm.GetTypes();
\r
65 // examine all the public types
\r
66 foreach(Type t in asmTypes) {
\r
68 // find out which, if any, interfaces are "in" the type
\r
69 interfaces= t.GetInterfaces();
\r
70 if (null != interfaces){
\r
71 // look for the interface we want to discover
\r
72 foreach (Type iface in interfaces) {
\r
73 // this area seems to throw an exception sometimes, just ignore it
\r
75 if (iface.FullName.ToLower() == args[0].ToLower()) {
\r
76 // find out if this type is the one which "declares" the interface
\r
77 map = t.GetInterfaceMap(iface);
\r
78 if (map.TargetMethods[0].DeclaringType.FullName == t.FullName){
\r
79 // if so, then we found a class to report
\r
80 implementingTypes.Add(t.FullName);
\r
89 // sort the list to make it easier to find what you are looking for
\r
90 implementingTypes.Sort();
\r
91 Console.WriteLine(XMLUtil.ToXML(implementingTypes, "Type", "ImplementingTypes"));
\r
94 private static void Usage() {
\r
96 "Mono Interface Discovery Tool\n" +
\r
97 "usage: ifacedisco [--asm assembly] interface\n\n" +
\r
98 " The full path to 'assembly' should be specified when using --asm.\n" +
\r
99 " If 'assembly' is not specified, the assembly that contains System.Object will be used.\n" +
\r
100 " Use the fully qualified form for 'interface', e.g. System.Runtime.Serialization.ISerializable\n"
\r
104 } // class IFaceDisco
\r
105 } // namespace Mono.Util
\r