2 // monop -- a semi-clone of javap
5 // Ben Maurer (bmaurer@users.sourceforge.net)
12 using System.Reflection;
13 using System.Collections;
14 using System.CodeDom.Compiler;
18 static string assembly;
20 // very common namespaces, all in corlib
21 static readonly string [] v_common_ns = {
29 static readonly string [] common_assemblies = {
36 static readonly string [] common_ns = {
43 static Type GetType (string tname, bool ignoreCase)
46 if (assembly != null){
47 Assembly a = Assembly.Load (assembly);
48 t = a.GetType (tname, false, ignoreCase);
50 t = Type.GetType (tname, false, ignoreCase);
55 static Type GetType (string tname)
57 return GetType (tname, false);
60 static void PrintTypes (string assembly)
62 Assembly a = Assembly.Load (assembly);
63 Type [] types = a.GetExportedTypes ();
65 foreach (Type t in types)
66 Console.WriteLine (t.FullName);
68 Console.WriteLine ("\nTotal: {0} types.", types.Length);
71 static void Main (string [] args)
73 if (args.Length < 1) {
74 Console.WriteLine ("monop [-r:Assembly] [class-name]");
78 IndentedTextWriter o = new IndentedTextWriter (Console.Out, " ");
81 if (args [0].StartsWith ("-r:")){
83 assembly = args [0].Substring (3);
85 if (args.Length == 1) {
86 PrintTypes (assembly);
91 if (args.Length < i+1){
92 Console.WriteLine ("Usage is: monop [-r:Assembly] [class-name]");
96 string tname = args [i];
97 Type t = GetType (tname);
100 // Try some very common ones, dont load anything
101 foreach (string ns in v_common_ns) {
102 t = GetType (ns + "." + tname, true);
108 if (assembly != null){
109 Console.WriteLine ("Did not find type in assembly");
113 foreach (string assm in common_assemblies) {
115 Assembly a = Assembly.Load (assm);
116 t = a.GetType (tname, false, true);
119 foreach (string ns in common_ns) {
120 t = a.GetType (ns + "." + tname, false, true);
122 Console.WriteLine ("(using class from {0})", ns);
132 Console.WriteLine ("Could not find {0}", tname);
137 // This gets us nice buffering
139 StreamWriter sw = new StreamWriter (Console.OpenStandardOutput (), Console.Out.Encoding);
140 new Outline (t, sw).OutlineType ();