.TP
.I \-\-runtime\-version
Print runtime version.
+.TP
+.I \-xa
+Sets the lookup path to the Xamarin.Android directory. This will
+load both the mscorlib from there, and search assemblies in that directory.
+.TP
+.I \-xi
+Sets the lookup path to the Xamarin.iOS directory. This will
+load both the mscorlib from there, and search assemblies in that directory.
.PP
.SH DESCRIPTION
Monop is a tool that allows you to view the outline of a class. You can see the
include ../../build/rules.make
PROGRAM = monop.exe
+LOCAL_MCS_FLAGS += -d:NO_AUTHENTICODE,STATIC,NO_SYMBOL_WRITER
CLEAN_FILES = monop.exe monop2.exe *.mdb
using System;
using System.Collections;
+#if STATIC
+using Type=IKVM.Reflection.Type;
+#endif
class TypeSorter : IComparer
{
//
// monop -- a semi-clone of javap
//
+// TODO:
+// Dump all attributes.
+//
// Authors:
// Ben Maurer (bmaurer@users.sourceforge.net)
// John Luke (john.luke@gmail.com)
using System.Collections;
using System.Diagnostics;
using System.IO;
-using System.Reflection;
+using IKVM.Reflection;
using System.Text;
using Mono.CSharp;
+using Type=IKVM.Reflection.Type;
class MonoP {
+ static Universe universe = new Universe(UniverseOptions.EnableFunctionPointers | UniverseOptions.ResolveMissingMembers | UniverseOptions.DisablePseudoCustomAttributeRetrieval);
+ static Assembly mscorlib;
+ static Type obsolete_attribute;
static string assembly;
// very common namespaces, all in corlib
"System.Collections",
"System.Reflection",
"System.Text",
- "System.IO"
+ "System.IO",
};
static readonly string [] common_assemblies = {
static readonly string [] common_ns = {
"System.Xml",
"System.Web",
+ "Foundation",
+ "CoreFoundation",
+ "CoreGraphics",
+ "UIKit",
"Gtk",
- "GLib"
+ "GLib",
};
static Type GetType (string tname, bool ignoreCase)
if (assembly != null) {
Assembly a = GetAssembly (assembly, true);
t = a.GetType (tname, false, ignoreCase);
- } else
- t = Type.GetType (tname, false, ignoreCase);
-
+ } else {
+ t = mscorlib.GetType (tname, false, ignoreCase);
+ }
return t;
}
string [] assemblies = GetKnownAssemblyNames ();
for (int i = 0; i < assemblies.Length; i++) {
+ Console.WriteLine ("Loading {0}", assemblies[i]);
Assembly a = GetAssembly (assemblies [i], false);
if (a == null)
continue;
static string [] GetKnownAssemblyNames ()
{
+ Console.WriteLine (options.PublicDir);
+ if (options.Style == "xios" || options.Style == "xand"){
+ return Directory.GetFiles (options.PublicDir, "*.dll");
+ }
+
Process p = new Process ();
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
try {
// if it exists try to use LoadFrom
if (File.Exists (assembly))
- a = Assembly.LoadFrom (assembly);
- // if it looks like a fullname try that
- else if (assembly.Split (',').Length == 4)
- a = Assembly.Load (assembly);
- // see if MONO_PATH has it
+ a = universe.LoadFile (assembly);
else
a = LoadFromMonoPath (assembly);
} catch {
// ignore exception it gets handled below
}
- // last try partial name
- // this (apparently) is exception safe
- if (a == null)
- a = Assembly.LoadWithPartialName (assembly);
-
if (a == null && exit) {
Console.WriteLine ("Could not load {0}", MonoP.assembly);
Environment.Exit (1);
foreach (string path in paths) {
string apath = Path.Combine (path, assembly);
if (File.Exists (apath))
- return Assembly.LoadFrom (apath);
+ return universe.LoadFile (apath);
}
return null;
}
Console.WriteLine ();
Console.WriteLine ("Assembly Information:");
- object[] cls = a.GetCustomAttributes (typeof (CLSCompliantAttribute), false);
- if (cls.Length > 0) {
- CLSCompliantAttribute cca = cls[0] as CLSCompliantAttribute;
- if (cca.IsCompliant)
- Console.WriteLine ("[CLSCompliant]");
- }
-
foreach (string ai in a.ToString ().Split (','))
Console.WriteLine (ai.Trim ());
int obsolete_count = 0;
foreach (Type t in types) {
- if (filter_obsolete && t.IsDefined (typeof (ObsoleteAttribute), false))
- obsolete_count ++;
- else
+ if (filter_obsolete && t.IsDefined (obsolete_attribute, false))
+ obsolete_count++;
+ else
Console.WriteLine (t.FullName);
}
internal static void Completion (string prefix)
{
- foreach (Type t in typeof (object).Assembly.GetExportedTypes ()) {
+ foreach (Type t in mscorlib.GetExportedTypes ()) {
if (t.Name.StartsWith (prefix)) {
if (Array.IndexOf (v_common_ns, t.Namespace) != -1) {
Console.WriteLine (t.Name);
{
Assembly a = GetAssembly (assembly, true);
- object[] cls = a.GetCustomAttributes (typeof (CLSCompliantAttribute), false);
- if (cls.Length > 0) {
- CLSCompliantAttribute cca = cls[0] as CLSCompliantAttribute;
- if (cca.IsCompliant)
- Console.WriteLine ("[CLSCompliant]");
- }
-
foreach (string ai in a.ToString ().Split (','))
Console.WriteLine (ai.Trim ());
var sw = new StreamWriter (Console.OpenStandardOutput (), Console.Out.Encoding);
foreach (Type t in types) {
- if (filter_obsolete && t.IsDefined (typeof (ObsoleteAttribute), false))
+ if (filter_obsolete && t.IsDefined (obsolete_attribute, false))
continue;
- new Outline (t, sw, true, show_private, filter_obsolete).OutlineType ();
+ new Outline (universe, mscorlib, t, sw, true, show_private, filter_obsolete).OutlineType ();
}
sw.Flush ();
}
+
+ static Options options = new Options ();
static void Main (string [] args)
{
- Options options = new Options ();
if (!options.ProcessArgs (args))
return;
+ if (options.Style == null)
+ mscorlib = universe.LoadFile (typeof (int).Assembly.Location);
+ else
+ mscorlib = universe.LoadFile (Path.Combine (options.PublicDir, "mscorlib.dll"));
+
+ obsolete_attribute = mscorlib.GetType ("System.ObsoleteAttribute");
+
if (options.AssemblyReference != null) {
assembly = options.AssemblyReference;
}
}
}
-
+
string message = null;
string tname = options.Type;
Type t = null;
int count;
+
if (options.Search) {
string matches = SearchTypes (tname, ref t, out count);
foreach (string assm in GetKnownAssemblyNames ()) {
try {
Assembly a = GetAssembly (assm, false);
+ if (a == null)
+ continue;
t = a.GetType (tname, false, true);
if (t != null) {
message = String.Format ("{0} is included in the {1} assembly.",
goto found;
}
}
- } catch {
+ } catch (Exception e){
+ Console.WriteLine ("Failure: " + e);
}
}
}
// This gets us nice buffering
//
StreamWriter sw = new StreamWriter (Console.OpenStandardOutput (), Console.Out.Encoding);
- new Outline (t, sw, options.DeclaredOnly, options.ShowPrivate, options.FilterObsolete).OutlineType ();
+ new Outline (universe, mscorlib, t, sw, options.DeclaredOnly, options.ShowPrivate, options.FilterObsolete).OutlineType ();
sw.Flush ();
if (message != null)
options.cs
outline.cs
TypeSorter.cs
+../../class/Mono.CompilerServices.SymbolWriter/MonoSymbolFile.cs
+../../class/Mono.CompilerServices.SymbolWriter/MonoSymbolTable.cs
+../../class/Mono.CompilerServices.SymbolWriter/SourceMethodBuilder.cs
+
+../../class/Mono.Security/Mono.Security.Cryptography/CryptoConvert.cs
+../../../external/ikvm/reflect/*.cs
+../../../external/ikvm/reflect/Emit/*.cs
+../../../external/ikvm/reflect/Metadata/*.cs
+../../../external/ikvm/reflect/Reader/*.cs
+../../../external/ikvm/reflect/Writer/*.cs
+../../../external/ikvm/reflect/Impl/ITypeOwner.cs
+../../../external/ikvm/reflect/Impl/SymbolSupport.cs
public bool ShowPrivate = false;
public string AssemblyReference = null;
public string Type = null;
+ public string PublicDir = null;
+ public string Style = null;
public Options ()
{
for (int i = 0; i < args.Length; i++) {
switch (args[i]) {
- case "-h":
- case "--help":
- PrintHelp ();
- return false;
- case "--runtime-version":
- PrintRuntimeVersion ();
- return false;
- case "-d":
- case "--declared-only":
- DeclaredOnly = true;
- break;
- case "--filter-obsolete":
- case "-f":
- FilterObsolete = true;
- break;
- case "-p":
- case "--private":
- ShowPrivate = true;
- break;
- case "--refs":
- PrintRefs = true;
- break;
- case "-s":
- case "-k":
- case "--search":
- Search = true;
- break;
- case "-c":
- i++;
- if (i < args.Length)
- MonoP.Completion (args[i]);
- return false;
- case "-r":
- i++;
- if (i < args.Length)
- AssemblyReference = args[i];
- break;
- case "-a":
- ShowAll = true;
+ case "-h":
+ case "--help":
+ PrintHelp ();
+ return false;
+ case "--runtime-version":
+ PrintRuntimeVersion ();
+ return false;
+ case "-d":
+ case "--declared-only":
+ DeclaredOnly = true;
+ break;
+ case "--filter-obsolete":
+ case "-f":
+ FilterObsolete = true;
+ break;
+ case "-p":
+ case "--private":
+ ShowPrivate = true;
+ break;
+ case "--refs":
+ PrintRefs = true;
+ break;
+ case "-xi":
+ PublicDir = "/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/Xamarin.iOS";
+ Style = "xios";
+ break;
+ case "-xa":
+ PublicDir = "/Library/Frameworks/Xamarin.iOS.framework/Versions/Current/lib/mono/2.1";
+ Style = "xand";
+ break;
+ case "-s":
+ case "-k":
+ case "--search":
+ Search = true;
+ break;
+ case "-c":
+ i++;
+ if (i < args.Length)
+ MonoP.Completion (args[i]);
+ return false;
+ case "-r":
+ i++;
+ if (i < args.Length)
+ AssemblyReference = args[i];
+ break;
+ case "-a":
+ ShowAll = true;
+ break;
+ default:
+ if (args[i].StartsWith ("-r:") || args[i].StartsWith ("/r:")) {
+ AssemblyReference = args [i].Substring (3);
break;
- default:
- if (args[i].StartsWith ("-r:") || args[i].StartsWith ("/r:")) {
- AssemblyReference = args [i].Substring (3);
- break;
- }
-
- // The first unrecognizable option becomes
- // the type to look up
- if (Type == null) {
- Type = args[i];
- break;
- }
-
- // others are ignored
- Console.WriteLine ("ignored: {0}", args[i]);
+ }
+
+ // The first unrecognizable option becomes
+ // the type to look up
+ if (Type == null) {
+ Type = args[i];
break;
+ }
+
+ // others are ignored
+ Console.WriteLine ("ignored: {0}", args[i]);
+ break;
}
}
Console.WriteLine ("\t--refs\t\t\tPrint a list of the referenced assemblies for an assembly");
Console.WriteLine ("\t--runtime-version\tPrint runtime version");
Console.WriteLine ("\t--search,-s,-k\t\tSearch through all known namespaces");
+ Console.WriteLine ("\t--xi\t\tSet search style to Xamarin.iOS");
+ Console.WriteLine ("\t--xa\t\tSet search style to Xamarin.Android");
Console.WriteLine ("\t--a\t\tShows all the types declare in the specified assembly");
}
}
//
using System;
-using System.Reflection;
using System.Collections;
using System.CodeDom.Compiler;
using System.IO;
using System.Text;
+#if STATIC
+using IKVM.Reflection;
+using Type=IKVM.Reflection.Type;
+#else
+using System.Reflection;
+#endif
namespace Mono.CSharp {
public class Outline {
-
bool declared_only;
bool show_private;
bool filter_obsolete;
IndentedTextWriter o;
Type t;
+ Type type_multicast_delegate, type_object, type_value_type, type_int, type_flags_attribute, type_obsolete_attribute, type_param_array_attribute;
+#if STATIC
+ Universe universe;
+ Assembly mscorlib;
+
+ public Outline (Universe universe, Assembly mscorlib, Type t, TextWriter output, bool declared_only, bool show_private, bool filter_obsolete)
+ {
+ if (universe == null)
+ throw new ArgumentNullException ("universe");
+ if (mscorlib == null)
+ throw new ArgumentNullException ("mscorlib");
+ this.universe = universe;
+ this.mscorlib = mscorlib;
+ this.t = t;
+ this.o = new IndentedTextWriter (output, "\t");
+ this.declared_only = declared_only;
+ this.show_private = show_private;
+ this.filter_obsolete = filter_obsolete;
+
+ type_multicast_delegate = mscorlib.GetType("System.MulticastDelegate");
+ type_object = mscorlib.GetType ("System.Object");
+ type_value_type = mscorlib.GetType ("System.ValueType");
+ type_int = mscorlib.GetType ("System.Int32");
+ type_flags_attribute = mscorlib.GetType ("System.FlagsAttribute");
+ type_obsolete_attribute = mscorlib.GetType ("System.ObsoleteAttribute");
+ type_param_array_attribute = mscorlib.GetType ("System.ParamArrayAttribute");
+ }
+#else
public Outline (Type t, TextWriter output, bool declared_only, bool show_private, bool filter_obsolete)
{
this.t = t;
this.declared_only = declared_only;
this.show_private = show_private;
this.filter_obsolete = filter_obsolete;
+
+ type_multicast_delegate = typeof (System.MulticastDelegate);
+ type_object = typeof (object);
+ type_value_type = typeof (ValueType);
+ type_int = typeof (int);
+ type_flags_attribute = typeof (FlagsAttribute);
+ type_obsolete_attribute = typeof (ObsoleteAttribuet);
+ type_param_array_attribute = typeof (ParamArrayAttribute);
}
+#endif
public void OutlineType ()
{
OutlineAttributes ();
o.Write (GetTypeVisibility (t));
- if (t.IsClass && !t.IsSubclassOf (typeof (System.MulticastDelegate))) {
+ if (t.IsClass && !t.IsSubclassOf (type_multicast_delegate)) {
if (t.IsSealed)
o.Write (t.IsAbstract ? " static" : " sealed");
else if (t.IsAbstract)
Type [] interfaces = (Type []) Comparer.Sort (TypeGetInterfaces (t, declared_only));
Type parent = t.BaseType;
- if (t.IsSubclassOf (typeof (System.MulticastDelegate))) {
+ if (t.IsSubclassOf (type_multicast_delegate)) {
MethodInfo method;
method = t.GetMethod ("Invoke");
}
o.Write (GetTypeName (t));
- if (((parent != null && parent != typeof (object) && parent != typeof (ValueType)) || interfaces.Length != 0) && ! t.IsEnum) {
+ if (((parent != null && parent != type_object && parent != type_value_type) || interfaces.Length != 0) && ! t.IsEnum) {
first = true;
o.Write (" : ");
- if (parent != null && parent != typeof (object) && parent != typeof (ValueType)) {
+ if (parent != null && parent != type_object && parent != type_value_type) {
o.Write (FormatType (parent));
first = false;
}
}
if (t.IsEnum) {
- Type underlyingType = System.Enum.GetUnderlyingType (t);
- if (underlyingType != typeof (int))
+ Type underlyingType = t.GetEnumUnderlyingType ();
+ if (underlyingType != type_int)
o.Write (" : {0}", FormatType (underlyingType));
}
WriteGenericConstraints (t.GetGenericArguments ());
if (first)
o.WriteLine ();
first = false;
-
+
+#if STATIC
+ new Outline (universe, mscorlib, ntype, o, declared_only, show_private, filter_obsolete).OutlineType ();
+#else
new Outline (ntype, o, declared_only, show_private, filter_obsolete).OutlineType ();
+#endif
}
o.Indent--; o.WriteLine ("}");
if (t.IsSerializable)
o.WriteLine ("[Serializable]");
- if (t.IsDefined (typeof (System.FlagsAttribute), true))
+ if (t.IsDefined (type_flags_attribute, true))
o.WriteLine ("[Flags]");
- if (t.IsDefined (typeof (System.ObsoleteAttribute), true))
+ if (t.IsDefined (type_obsolete_attribute, true))
o.WriteLine ("[Obsolete]");
}
void OutlineMemberAttribute (MemberInfo mi)
{
- if (!mi.IsDefined (typeof (System.ObsoleteAttribute), false))
- return;
- var oa = mi.GetCustomAttributes (typeof (System.ObsoleteAttribute), false) [0] as ObsoleteAttribute;
- var msg = oa.Message;
- o.WriteLine ("[Obsolete{0}]", msg == null || msg == "" ? "" : string.Format ("(\"{0}\")", msg));
+ var attrs = mi.GetCustomAttributesData ();
+ if (attrs.Count > 0)
+ o.WriteLine ("");
+
+ foreach (var attr in attrs)
+ o.WriteLine (attr);
}
void OutlineEvent (EventInfo ei)
if (p.ParameterType.IsByRef) {
o.Write (p.IsOut ? "out " : "ref ");
o.Write (FormatType (p.ParameterType.GetElementType ()));
- } else if (p.IsDefined (typeof (ParamArrayAttribute), false)) {
+ } else if (p.IsDefined (type_param_array_attribute, false)) {
o.Write ("params ");
o.Write (FormatType (p.ParameterType));
} else {
o.Write (" ");
o.Write (fi.Name);
if (fi.IsLiteral) {
- object v = fi.GetValue (this);
+ object v = fi.GetRawConstantValue ();
// TODO: Escape values here
o.Write (" = ");
else if (v is string)
o.Write ("\"{0}\"", v);
else
- o.Write (fi.GetValue (this));
+ o.Write (fi.GetRawConstantValue ());
}
o.Write (";");
}
return null;
}
- static string GetTypeKind (Type t)
+ string GetTypeKind (Type t)
{
if (t.IsEnum)
return "enum";
if (t.IsClass) {
- if (t.IsSubclassOf (typeof (System.MulticastDelegate)))
+ if (t.IsSubclassOf (type_multicast_delegate))
return "delegate";
else
return "class";
return t.ToString ();
if (!type.StartsWith ("System.")) {
+ if (type.IndexOf (".") == -1)
+ return type;
if (t.Namespace == this.t.Namespace)
return t.Name;
return type;
GenericParameterAttributes.DefaultConstructorConstraint
};
- if (t.BaseType != typeof (object) || ifaces.Length != 0 || attrs != 0) {
+ if (t.BaseType != type_object || ifaces.Length != 0 || attrs != 0) {
o.Write (" where ");
o.Write (FormatType (t));
o.Write (" : ");
}
- if (t.BaseType != typeof (object)) {
+ if (t.BaseType != type_object) {
o.Write (FormatType (t.BaseType));
first = false;
}
if (show_private)
return true;
- if (filter_obsolete && mi.IsDefined (typeof (ObsoleteAttribute), false))
+ if (filter_obsolete && mi.IsDefined (type_obsolete_attribute, false))
return false;
switch (mi.MemberType) {
Type type1 = (Type) a;
Type type2 = (Type) b;
- if (type1.IsSubclassOf (typeof (System.MulticastDelegate)) != type2.IsSubclassOf (typeof (System.MulticastDelegate)))
- return (type1.IsSubclassOf (typeof (System.MulticastDelegate)))? -1:1;
return string.Compare (type1.Name, type2.Name);
}