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