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 foreach (Type t in a.GetExportedTypes ())
64 Console.WriteLine (t.FullName);
67 static void Main (string [] args)
69 if (args.Length < 1) {
70 Console.WriteLine ("monop [-r:Assembly] [class-name]");
74 IndentedTextWriter o = new IndentedTextWriter (Console.Out, " ");
77 if (args [0].StartsWith ("-r:")){
79 assembly = args [0].Substring (3);
81 if (args.Length == 1) {
82 PrintTypes (assembly);
87 if (args.Length < i+1){
88 Console.WriteLine ("Usage is: monop [-r:Assembly] [class-name]");
92 string tname = args [i];
93 Type t = GetType (tname);
96 // Try some very common ones, dont load anything
97 foreach (string ns in v_common_ns) {
98 t = GetType (ns + "." + tname, true);
104 if (assembly != null){
105 Console.WriteLine ("Did not find type in assembly");
109 foreach (string assm in common_assemblies) {
111 Assembly a = Assembly.Load (assm);
112 t = a.GetType (tname, false, true);
115 foreach (string ns in common_ns) {
116 t = a.GetType (ns + "." + tname, false, true);
118 Console.WriteLine ("(using class from {0})", ns);
128 Console.WriteLine ("Could not find {0}", tname);
133 // This gets us nice buffering
135 StreamWriter sw = new StreamWriter (Console.OpenStandardOutput (), Console.Out.Encoding);
136 new Outline (t, sw).OutlineType ();