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 Main (string [] args)
62 if (args.Length < 1) {
63 Console.WriteLine ("monop [-r:Assembly] class-name");
67 IndentedTextWriter o = new IndentedTextWriter (Console.Out, " ");
70 if (args [0].StartsWith ("-r:")){
72 assembly = args [0].Substring (3);
75 if (args.Length < i+1){
76 Console.WriteLine ("Usage is: monop [-r:Assembly] class-name");
80 string tname = args [i];
81 Type t = GetType (tname);
84 // Try some very common ones, dont load anything
85 foreach (string ns in v_common_ns) {
86 t = GetType (ns + "." + tname, true);
92 if (assembly != null){
93 Console.WriteLine ("Did not find type in assembly");
97 foreach (string assm in common_assemblies) {
99 Assembly a = Assembly.Load (assm);
100 t = a.GetType (tname, false, true);
103 foreach (string ns in common_ns) {
104 t = a.GetType (ns + "." + tname, false, true);
106 Console.WriteLine ("(using class from {0})", ns);
116 Console.WriteLine ("Could not find {0}", tname);
121 // This gets us nice buffering
123 StreamWriter sw = new StreamWriter (Console.OpenStandardOutput (), Console.Out.Encoding);
124 new Outline (t, sw).OutlineType ();