When I wasn't recovering from stomach flu, anyway...
All in all, a good Christmas.
Summary:
- Made tools/makefile.gnu recursive, much like the top-level makefile.gnu.
This was principally done so that the type-reflector install target could
install additional files (currently it installs type-reflector.exe and
type-reflector.exe.config; this may expand in the future).
- Massive cleanup/improvements to type-reflector
The biggest news is that a Gtk# front-end exists for type-reflector now. It
is incomplete (due to my learning Gtk# with this program) and needs
improvement, but it works... Sort of.
It's not enabled by default, as I don't want to require that the
Gtk#/Gnome#/Glade# assemblies be available to build mcs from CVS.
To enable the type-reflector Gtk# front-end, do two things:
- Rebuild type-reflector: cd tools/type-reflector && make -f makefile.gnu gui
- When running, specify the --displayer=gtk parameter, e.g.
type-reflector.exe --displayer=gtk -S .
svn path=/trunk/mcs/; revision=10020
+2002-12-31 Jonathan Pryor <jonpryor@vt.edu>
+
+ * makefile.gnu: Add support for DIRS to all, install targets. This was done
+ so type-reflector's install target could be independent/self-contained.
+
2002-12-27 Sebastien Pouliot <spouliot@videotron.ca>
* ASN1.cs: New. Classes to manipulate Abstract Syntax Notation 1
MONO_TOOLS = monostyle.exe GenerateDelegate.exe EnumCheck.exe IFaceDisco.exe ./SqlSharp/sqlsharp.exe secutil.exe Cert2Spc.exe
+DIRS = type-reflector
+
# tools commented here because they were unable to build under linux
#MONO_TOOLS = monostyle.exe verifier.exe GenerateDelegate.exe EnumCheck.exe IFaceDisco.exe ./type-reflector/type-reflector.exe ./corcompare/CorCompare.exe ./SqlSharp/SqlSharpCli.exe
+all: tools
+ for i in $(DIRS) ; do \
+ $(MAKE) -C $$i -f makefile.gnu $@ || exit 1; \
+ done
+
linx: $(MONO_TOOLS)
-all: $(MONO_TOOLS)
+tools: $(MONO_TOOLS)
windows: $(MONO_TOOLS)
for i in $(MONO_TOOLS) ; do \
($(INSTALL) -m 755 $$i $(prefix)/bin/) || exit 1; \
done
+ for i in $(DIRS) ; do \
+ $(MAKE) -C $$i -f makefile.gnu $@ || exit 1; \
+ done
monostyle.exe: monostyle.cs
$(CSC) $(CSCFLAGS) monostyle.cs
verifier.exe: verifier.cs
$(CSC) $(CSCFLAGS) verifier.cs
-./type-reflector/type-reflector.exe: dummy
- (cd type-reflector; make CSC=$(CSC))
-
./SqlSharp/sqlsharp.exe: dummy
(cd SqlSharp; make CSC=$(CSC))
clean:
(cd corcompare; make clean)
- (cd type-reflector; make clean)
(cd SqlSharp; make clean)
rm -f *.exe *.pdb *.dbg *.dll
rm -f cormissing.xml
rm -f ../../mono/doc/pending-classes.in
+ for i in $(DIRS) ; do \
+ $(MAKE) -C $$i -f makefile.gnu $@ || exit 1; \
+ done
dummy:
{
}
- protected override string GetTypeDescription (Type type, object instance)
- {
- StringBuilder sb = new StringBuilder ();
- GetAttributes (sb, type);
- sb.Append (base.GetTypeDescription (type, instance));
- return sb.ToString();
- }
-
- private void GetAttributes (StringBuilder sb, MemberInfo m)
- {
- GetAttributes (sb, m, true);
- }
-
- private void GetAttributes (StringBuilder sb, MemberInfo m, bool newline)
- {
- GetCilAttributes (sb, m, newline);
- sb.Append (GetCustomAttributes (m, "", newline));
- }
-
- private void GetCilAttributes (StringBuilder sb, MemberInfo m, bool newline)
- {
- Type t = m as Type;
- MethodBase mb = m as MethodBase;
- if (t != null)
- GetCilAttributes (sb, t, newline);
- else if (mb != null)
- GetCilAttributes (sb, mb, newline);
- }
-
- private void GetCilAttributes (StringBuilder sb, Type t, bool newline)
- {
- if (t.IsSerializable) {
- sb.Append ("[Serializable]");
- if (newline)
- sb.Append ("\n");
- }
- }
-
- private void GetCilAttributes (StringBuilder sb, MethodBase m, bool newline)
- {
- MethodImplAttributes attr = m.GetMethodImplementationFlags ();
- if ((attr & MethodImplAttributes.InternalCall) != 0) {
- sb.Append ("[MethodImplAttribute(MethodImplOptions.InternalCall)]");
- if (newline)
- sb.Append ("\n");
- }
- }
-
- protected override string GetBaseTypeDescription (Type type, object instance)
- {
- return ": " + type.Name;
- }
-
- protected override string GetInterfaceDescription (Type type, object instance)
- {
- return ", " + type.Name;
- }
-
- protected override string GetConstructorDescription (ConstructorInfo ctor, object instance)
- {
- StringBuilder sb = new StringBuilder ();
- GetAttributes (sb, ctor);
- GetMethodQualifiers (sb, ctor);
- sb.AppendFormat ("{0} ", ctor.DeclaringType.Name);
- GetMethodArgs (sb, ctor);
-
- return sb.ToString();
- }
-
- private void GetMethodQualifiers (StringBuilder sb, MethodBase m)
- {
- if (m.IsPublic)
- sb.Append ("public ");
- if (m.IsFamily)
- sb.Append ("protected ");
- if (m.IsAssembly)
- sb.Append ("internal ");
- if (m.IsPrivate)
- sb.Append ("private ");
- if (m.IsStatic)
- sb.Append ("static ");
- if (m.IsFinal)
- sb.Append ("sealed ");
- if (m.IsAbstract)
- sb.Append ("abstract ");
- else if (m.IsVirtual)
- sb.Append ("virtual ");
- }
-
- private void GetMethodArgs (StringBuilder sb, MethodBase m)
- {
- sb.Append ("(");
- ParameterInfo[] parms = m.GetParameters ();
- if (parms.Length != 0) {
- int cur = 0;
- foreach (ParameterInfo pi in parms) {
- sb.Append (GetParameterDescription (pi, pi));
- if (cur++ != (parms.Length-1))
- sb.Append (", ");
- }
- }
- sb.Append (")");
- }
+ protected override string LineComment {get {return "//";}}
- protected override string GetEventDescription (EventInfo e, object instance)
- {
- StringBuilder sb = new StringBuilder ();
- GetMethodQualifiers (sb, e.GetAddMethod (true));
- return String.Format ("{0}{1}{2} {3}",
- sb.ToString(),
- e.IsMulticast ? "event " : "",
- e.EventHandlerType,
- e.Name);
- }
-
- protected override string GetFieldDescription (FieldInfo field, object instance)
- {
- StringBuilder sb = new StringBuilder ();
+ protected override string KeywordClass {get {return "class";}}
+ protected override string KeywordEnum {get {return "enum";}}
+ protected override string KeywordValueType {get {return "struct";}}
+ protected override string KeywordInterface {get {return "interface";}}
+ protected override string KeywordInherits {get {return ":";}}
+ protected override string KeywordImplements {get {return ",";}}
+ protected override string KeywordMulticast {get {return "event";}}
+ protected override string KeywordStatementTerminator {get {return ";";}}
+ protected override string KeywordStatementSeparator {get {return ",";}}
- GetAttributes (sb, field);
-
- if (!field.DeclaringType.IsEnum || field.IsSpecialName) {
- if (field.IsPublic)
- sb.Append ("public ");
- if (field.IsPrivate)
- sb.Append ("private ");
- if (field.IsAssembly)
- sb.Append ("internal ");
- if (field.IsFamily)
- sb.Append ("protected ");
- if (field.IsLiteral)
- sb.Append ("const ");
- else if (field.IsStatic)
- sb.Append ("static ");
-
- sb.AppendFormat ("{0} ", field.FieldType);
- }
-
- sb.AppendFormat ("{0}", field.Name);
-
- try {
- sb.AppendFormat (" = {0}", GetValue (field.GetValue (instance)));
- }
- catch {
- }
-
- if (!field.DeclaringType.IsEnum || field.IsSpecialName)
- sb.Append (";");
- else
- sb.Append (",");
-
- return sb.ToString ();
- }
-
- protected override string GetMethodDescription (MethodInfo method, object instance)
- {
- StringBuilder sb = new StringBuilder ();
-
- if (method.IsSpecialName)
- sb.Append ("/* Method is a specially named method:\n");
-
- GetAttributes (sb, method);
- if (method.ReturnTypeCustomAttributes != null) {
- sb.Append (GetCustomAttributes (method.ReturnTypeCustomAttributes, "return: ", true));
- }
- GetMethodQualifiers (sb, method);
- sb.AppendFormat ("{0} {1} ", method.ReturnType, method.Name);
- GetMethodArgs (sb, method);
-
- if (method.GetParameters().Length == 0) {
- try {
- object r = method.Invoke (instance, null);
- string s = GetValue (r);
- sb.AppendFormat ("={0}", s);
- }
- catch {
- }
- }
-
- if (method.IsSpecialName) {
- sb.Append ("\n */");
- }
-
- return sb.ToString();
- }
-
- protected override string GetParameterDescription (ParameterInfo param, object instance)
- {
- StringBuilder sb = new StringBuilder ();
-
- sb.Append (GetCustomAttributes (param, "", false));
- if (param.IsOut)
- sb.Append ("out ");
- sb.AppendFormat ("{0} {1}", param.ParameterType, param.Name);
-
- return sb.ToString();
- }
-
- protected override string GetPropertyDescription (PropertyInfo property, object instance)
- {
- StringBuilder sb = new StringBuilder ();
- GetAttributes (sb, property);
- GetMethodQualifiers (sb, property.GetAccessors(true)[0]);
+ protected override string QualifierPublic {get {return "public";}}
+ protected override string QualifierFamily {get {return "protected";}}
+ protected override string QualifierAssembly {get {return "internal";}}
+ protected override string QualifierPrivate {get {return "private";}}
+ protected override string QualifierFinal {get {return "sealed";}}
+ protected override string QualifierStatic {get {return "static";}}
+ protected override string QualifierLiteral {get {return "const";}}
+ protected override string QualifierAbstract {get {return "abstract";}}
+ protected override string QualifierVirtual {get {return "virtual";}}
- sb.AppendFormat ("{0} {1} {{", property.PropertyType, property.Name);
- if (property.CanRead) {
- sb.Append ("get");
- try {
- sb.AppendFormat (" /* = {0} */", GetValue (property.GetValue (instance, null)));
- }
- catch {
- }
- sb.Append ("; ");
- }
- if (property.CanWrite)
- sb.Append ("set; ");
- sb.Append ("}}");
+ private static readonly string[] attributeDelimeters = new string[]{"[", "]"};
- return sb.ToString();
+ protected override string[] AttributeDelimeters {
+ get {return attributeDelimeters;}
}
- protected override string GetReturnValueDescription (NodeInfo n)
+ protected override string GetConstructorName (ConstructorInfo ctor)
{
- return string.Format ("/* ReturnValue={0} */", GetOtherDescription (n));
+ return ctor.DeclaringType.Name;
}
}
}
+2002-12-31 Jonathan Pryor <jonpryor@vt.edu>
+ * ConsoleTypeDisplayer.cs: New; Display reflection information to the console
+ * CSharpNodeFormatter.cs: Most formatting information was moved to
+ LanguageNodeFormatter.cs (to permit sharing with the VBNodeFormatter)
+ * ExplicitNodeFinder.cs: Updates due to NodeFinder changes.
+ * Factories.cs: Add new "Displayer" factory, remove "Factory" from name of
+ factory objects; the fact they're in a "Factories" class should be
+ sufficient.
+ * IndentingTextWriter.cs: Ensure that if a string sent to Write or WriteLine
+ contains embedded newlines, that we indent the text after the newlines
+ appropriately.
+ * ITypeDisplayer.cs: New; Abstraction for displaying reflection information
+ * LanguageNodeFormatter.cs: Massive cleanup & Consolidation of features.
+ Now works as a control class for generating Language-like output,
+ simplifying C# and VB.NET language formatting.
+ * Makefile: Most contents moved to `makefile.core'; just sets variables and
+ forwards operation to `makefile.core'.
+ * Node.cs: Debugging ToString() implementation
+ * NodeFinder.cs: Change virtual Get* methods to Add* methods, as
+ they're supposed to Add stuff to the Collection object passed as the first
+ paramter, not actually return ("get") anything; Removed `maxDepth', as
+ it's not used in the NodeFinder.
+ * NodeFormatter.cs: Move language-like attribute formatting to
+ LanguageNodeFormatter; check that base type isn't null before accessing
+ its name; recent CVS snapshots have the base object of interfaces as the
+ null object (before it was System.Object); this may be a mono bug.
+ * NodeInfo.cs: Debugging ToString() implementation
+ * ProgramOptions.cs: Make classes public, not internal
+ * README: Updates
+ * ReflectionNodeFinder.cs: Updates due to NodeFinder changes.
+ * TestTypes.cs: More tests
+ * TypeDisplayer.cs: New; Helper implementation for ITypeDisplayer
+ * TypeFactory.cs: Trace/log the exception generated when creating a new
+ object
+ * TypeLoader.cs: Take a list of types to search for, not just a single type.
+ This simplifies looking for types, as we can do a single search for all
+ types, instead of separate searches for each type. Also improves
+ performance.
+ * TypeReflectorApp.cs: New; Formerly ConsoleOutput.cs; sets things in motion
+ * TypeReflectorOptions.cs: Make public; Add --displayer argument
+ * VBNodeFormatter.cs: New; Displayer reflection information in VB.NET
+ * gtk: new directory for Gtk# front-end
+ * makefile.core: New; Common makefile rules shared between Makefile,
+ makefile.gnu
+ * makefile.gnu: New; makefile used on Linux, used by tools/makefile.gnu for
+ recursive makes.
+ * type-reflector.exe.config: Add new switch, sample listener
+
2002-12-21 Jonathan Pryor <jonpryor@vt.edu>
* ConsoleOutput.cs: Use a Switch for trace messages.
* ExplicitNodeFinder.cs: Use a Switch for trace messages.
+++ /dev/null
-//
-// ConsoleOutput.cs:
-// Finds types and (optionally) shows reflection information about
-// the types.
-//
-// Author: Jonathan Pryor (jonpryor@vt.edu)
-//
-// (C) 2002 Jonathan Pryor
-//
-
-// #define TRACE
-
-using System;
-using System.Collections;
-using System.IO;
-using System.Diagnostics;
-using System.Reflection;
-using System.Text;
-using System.Text.RegularExpressions;
-
-namespace Mono.TypeReflector
-{
- public class ConsoleOutput {
-
- private static BooleanSwitch console = new BooleanSwitch ("console",
- "console-specific and command-line handling output");
-
- private static void TraceStringArray (string message, IEnumerable contents)
- {
- Trace.WriteLineIf (console.Enabled, message);
- foreach (string s in contents) {
- Trace.WriteLineIf (console.Enabled, " " + s);
- }
- }
-
- private static void PrintVersion ()
- {
- Console.WriteLine ("type-reflector 0.5");
- Console.WriteLine ("Written by Jonathan Pryor.");
- Console.WriteLine ();
- Console.WriteLine ("Copyright (C) 2002 Jonathan Pryor.");
- }
-
- private static void InitFactory ()
- {
- // TypeDisplayerFactory.Add ("explicit", typeof(ExplicitTypeDisplayer));
- // TypeDisplayerFactory.Add ("reflection", typeof(ReflectionTypeDisplayer));
- // TypeDisplayerFactory.Add ("c#", typeof(CSharpTypeDisplayer));
- Factories.FormatterFactory.Add ("default", typeof (DefaultNodeFormatter));
- Factories.FormatterFactory.Add ("csharp", typeof (CSharpNodeFormatter));
- Factories.FinderFactory.Add ("explicit", typeof (ExplicitNodeFinder));
- Factories.FinderFactory.Add ("reflection", typeof (ReflectionNodeFinder));
- }
-
- public static void Main (string[] args)
- {
- InitFactory ();
-
- TypeReflectorOptions options = new TypeReflectorOptions ();
-
- try {
- options.ParseOptions (args);
- } catch (Exception e) {
- Console.WriteLine (e.Message);
- Console.WriteLine ("See `{0} --help' for more information", ProgramOptions.ProgramName);
- // Console.WriteLine ("** Full Message continues:\n" + e);
- return;
- }
-
- if (options.FoundHelp) {
- Console.WriteLine (options.OptionsHelp);
- return;
- }
-
- if (options.DefaultAssemblies) {
- Console.WriteLine ("The default search assemblies are:");
- foreach (string s in TypeReflectorOptions.GetDefaultAssemblies ()) {
- Console.WriteLine (" {0}", s);
- }
- return;
- }
-
- if (options.Version) {
- PrintVersion ();
- return;
- }
-
- if (options.Types.Count == 0) {
- Console.WriteLine ("No types specified.");
- Console.WriteLine ("See `{0} --help' for more information", ProgramOptions.ProgramName);
- return;
- }
-
- TraceStringArray ("Search Assemblies: ", options.Assemblies);
- TraceStringArray ("Search for Types: ", options.Types);
-
- TypeLoader loader = new TypeLoader (options.Assemblies);
- loader.MatchBase = options.MatchBase;
- loader.MatchFullName = options.MatchFullName;
- loader.MatchClassName = options.MatchClassName;
- loader.MatchNamespace = options.MatchNamespace;
- loader.MatchMethodReturnType = options.MatchReturnType;
-
- IndentingTextWriter writer = new IndentingTextWriter (Console.Out);
-
- int depth = options.MaxDepth;
-
- INodeFormatter formatter = Factories.FormatterFactory.Create (options.Formatter);
- if (formatter == null) {
- Console.WriteLine ("Error: invalid formatter: " + options.Formatter);
- return;
- }
-
- NodeFinder f = (NodeFinder) Factories.FinderFactory.Create (options.Finder);
- if (f == null) {
- Console.WriteLine ("Error: invalid finder: " + options.Finder);
- return;
- }
-
- f.VerboseOutput = options.VerboseOutput;
- f.ShowBase = options.ShowBase;
- f.ShowConstructors = options.ShowConstructors;
- f.ShowEvents = options.ShowEvents;
- f.ShowFields = options.ShowFields;
- f.ShowInterfaces = options.ShowInterfaces;
- f.ShowMethods = options.ShowMethods;
- f.ShowProperties = options.ShowProperties;
- f.ShowTypeProperties = options.ShowTypeProperties;
- f.ShowInheritedMembers = options.ShowInheritedMembers;
- f.ShowNonPublic = options.ShowNonPublic;
- f.ShowMonoBroken = options.ShowMonoBroken;
- f.FlattenHierarchy = options.FlattenHierarchy;
- f.MaxDepth = options.MaxDepth;
-
- foreach (string t in options.Types) {
- try {
- ICollection typesFound = loader.LoadTypes (t);
- if (typesFound.Count > 0)
- foreach (Type type in loader.LoadTypes(t)) {
- // Console.WriteLine ("** displaying type: " + type);
- Node root = new Node (formatter,
- f);
- // new GroupingNodeFinder (f));
- // new ExplicitNodeFinder());
- // root.Extra = new NodeInfo (null, type, NodeTypes.Type);
- root.NodeInfo = new NodeInfo (null, type);
- ShowNode (root, writer, depth);
- }
- else
- Console.WriteLine ("Unable to find type `{0}'.", t);
- } catch (Exception e) {
- Console.WriteLine ("Unable to display type `{0}': {1}.", t, e.ToString());
- }
- }
- }
-
- private static void ShowNode (Node root, IndentingTextWriter writer, int maxDepth)
- {
- // Console.WriteLine ("** current max depth: " + maxDepth);
- writer.WriteLine (root.Description);
- if (maxDepth > 0) {
- using (Indenter i = new Indenter (writer)) {
- foreach (Node child in root.GetChildren()) {
- ShowNode (child, writer, maxDepth-1);
- }
- }
- }
- }
- }
-}
-
--- /dev/null
+//
+// ConsoleTypeDisplayer.cs:
+// Display types on the console.
+//
+// Author: Jonathan Pryor (jonpryor@vt.edu)
+//
+// (C) 2002 Jonathan Pryor
+//
+
+// #define TRACE
+
+using System;
+using System.Collections;
+using System.IO;
+using System.Diagnostics;
+using System.Reflection;
+using System.Text;
+using System.Text.RegularExpressions;
+
+namespace Mono.TypeReflector
+{
+ public class ConsoleTypeDisplayer : TypeDisplayer
+ {
+ private IndentingTextWriter writer = new IndentingTextWriter (Console.Out);
+
+ // `ReflectionTypeDisplayer.PrintTypeProperties' is recursive, but refrains
+ // from printing duplicates. Despite duplicate removal, the output for
+ // printing the Properties of System.Type is > 800K of text.
+ //
+ // 3 levels permits viewing Attribute values, but not the attributes of
+ // those attribute values.
+ //
+ // For example, 3 levels permits:
+ // class System.Type {depth 0}
+ // Properties: {depth 1}
+ // System.Reflection.MemberTypes MemberType {depth 2}
+ // - CanRead=True {depth 3}
+ // - CanWrite=False {depth 3}
+ // ...
+ private int maxDepth = 3;
+
+ public override int MaxDepth {
+ set {maxDepth = value;}
+ }
+
+ public override bool RequireTypes {
+ get {return true;}
+ }
+
+ public ConsoleTypeDisplayer ()
+ {
+ }
+
+ public override void Run ()
+ {
+ foreach (Assembly a in Assemblies) {
+ writer.WriteLine ("Assembly: FullName='{0}'; Location='{1}'",
+ a.FullName, a.Location);
+ using (Indenter i = Indent()) {
+ foreach (string ns in Namespaces(a)) {
+ writer.WriteLine ("Namespace: {0}", ns);
+ using (Indenter i2 = Indent()) {
+ foreach (Type type in Types (a, ns)) {
+ Node root = new Node (Formatter, Finder);
+ // new GroupingNodeFinder (f));
+ // new ExplicitNodeFinder());
+ // root.Extra = new NodeInfo (null, type, NodeTypes.Type);
+ root.NodeInfo = new NodeInfo (null, type);
+ ShowNode (root, writer, maxDepth);
+ writer.WriteLine ();
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private static void ShowNode (Node root, IndentingTextWriter writer, int maxDepth)
+ {
+ writer.WriteLine (root.Description);
+ if (maxDepth > 0) {
+ using (Indenter i = new Indenter (writer)) {
+ foreach (Node child in root.GetChildren()) {
+ ShowNode (child, writer, maxDepth-1);
+ }
+ }
+ }
+ }
+
+ private Indenter Indent ()
+ {
+ return new Indenter (writer);
+ }
+ }
+}
+
return count;
}
- protected override void GetTypeChildren (NodeInfoCollection c, NodeInfo parent, Type type)
+ protected override void AddTypeChildren (NodeInfoCollection c, NodeInfo parent, Type type)
{
object instance = parent.ReflectionInstance;
}
}
- protected override void GetFieldChildren (NodeInfoCollection c, NodeInfo parent, FieldInfo field)
+ protected override void AddFieldChildren (NodeInfoCollection c, NodeInfo parent, FieldInfo field)
{
Trace.WriteLineIf (info.Enabled, "Getting Field Children");
AddMemberChildren (parent, field, c);
}
}
- protected override void GetParameterChildren (NodeInfoCollection c, NodeInfo parent, ParameterInfo pi)
+ protected override void AddParameterChildren (NodeInfoCollection c, NodeInfo parent, ParameterInfo pi)
{
// TODO: handle custom attributes...
// c.Add (new NodeInfo (parent, pi, customAttributes, NodeTypes.Other));
AddMembers (parent, pi, "Position", c);
}
- protected override void GetConstructorChildren (NodeInfoCollection c, NodeInfo parent, ConstructorInfo node)
+ protected override void AddConstructorChildren (NodeInfoCollection c, NodeInfo parent, ConstructorInfo node)
{
AddMethodBaseChildren (parent, node, c);
}
- protected override void GetEventChildren (NodeInfoCollection c, NodeInfo parent, EventInfo node)
+ protected override void AddEventChildren (NodeInfoCollection c, NodeInfo parent, EventInfo node)
{
AddMemberChildren (parent, node, c);
AddMembers (parent, node, "Attributes", c);
AddMembers (parent, node, "IsSpecialName", c);
}
- protected override void GetMethodChildren (NodeInfoCollection c, NodeInfo parent, MethodInfo node)
+ protected override void AddMethodChildren (NodeInfoCollection c, NodeInfo parent, MethodInfo node)
{
AddMethodBaseChildren (parent, node, c);
AddMembers (parent, node, "ReturnType", c);
}
}
- protected override void GetPropertyChildren (NodeInfoCollection c, NodeInfo parent, PropertyInfo node)
+ protected override void AddPropertyChildren (NodeInfoCollection c, NodeInfo parent, PropertyInfo node)
{
AddMemberChildren (parent, node, c);
AddMembers (parent, node, "Attributes", c);
}
}
- public static FinderTypeFactory FinderFactory = new FinderTypeFactory ();
- public static FormatterTypeFactory FormatterFactory = new FormatterTypeFactory ();
+ public sealed class DisplayerTypeFactory : TypeFactory
+ {
+ public new ITypeDisplayer Create (object key)
+ {
+ return (ITypeDisplayer) base.Create (key);
+ }
+ }
+
+ public static FinderTypeFactory Finder = new FinderTypeFactory ();
+ public static FormatterTypeFactory Formatter = new FormatterTypeFactory ();
+ public static DisplayerTypeFactory Displayer = new DisplayerTypeFactory ();
}
}
--- /dev/null
+//
+// ITypeDisplayer.cs:
+// Framework interface for the displaying of types to a display device (e.g.
+// console or GUI program).
+//
+// Author: Jonathan Pryor (jonpryor@vt.edu)
+//
+// (C) 2002 Jonathan Pryor
+//
+
+using System;
+
+namespace Mono.TypeReflector
+{
+ public interface ITypeDisplayer
+ {
+ INodeFormatter Formatter {set;}
+ INodeFinder Finder {set;}
+ TypeReflectorOptions Options {set;}
+ int MaxDepth {set;}
+ bool RequireTypes {get;}
+
+ void AddType (Type n);
+
+ void Run ();
+ }
+}
+
public override void Write (string value)
{
+ string[] lines = value.Split ('\n');
+ _Write (lines[0]);
+ if (lines.Length > 1) {
+ WriteLine ();
+ for (int i = 1; i != lines.Length; ++i)
+ _WriteLine (lines[i]);
+ }
+ }
+
+ private void _Write (string value)
+ {
if (NeedIndent)
WriteIndent ();
_writer.Write (value);
- }
+ }
public override void WriteLine ()
{
public override void WriteLine (string value)
{
+ string[] lines = value.Split ('\n');
+ foreach (string s in lines)
+ _WriteLine (s);
+ }
+
+ private void _WriteLine (string value)
+ {
Trace.WriteLineIf (info.Enabled, String.Format(
"WriteLine: NeedIndent={0}", NeedIndent));
if (NeedIndent)
WriteIndent ();
_writer.WriteLine (value);
NeedIndent = true;
- }
+ }
}
public class Indenter : IDisposable {
namespace Mono.TypeReflector
{
- public class LanguageNodeFormatter : NodeFormatter {
+ public abstract class LanguageNodeFormatter : NodeFormatter {
+
+ protected abstract string LineComment {get;}
+
+ // [0] is open, [1] is close
+ protected abstract string[] AttributeDelimeters {get;}
+
+ protected abstract string KeywordClass {get;}
+ protected abstract string KeywordEnum {get;}
+ protected abstract string KeywordValueType {get;}
+ protected abstract string KeywordInterface {get;}
+ protected abstract string KeywordInherits {get;}
+ protected abstract string KeywordImplements {get;}
+ protected abstract string KeywordMulticast {get;}
+ protected abstract string KeywordStatementTerminator {get;}
+ protected abstract string KeywordStatementSeparator {get;}
+
+ protected abstract string QualifierPublic {get;}
+ protected abstract string QualifierFamily {get;}
+ protected abstract string QualifierAssembly {get;}
+ protected abstract string QualifierPrivate {get;}
+ protected abstract string QualifierStatic {get;}
+ protected abstract string QualifierFinal {get;}
+ protected abstract string QualifierAbstract {get;}
+ protected abstract string QualifierVirtual {get;}
+ protected abstract string QualifierLiteral {get;}
protected override string GetTypeDescription (Type type, object instance)
{
- return string.Format ("{0} {1}", GetTypeKeyword(type), type.Name);
+ StringBuilder sb = new StringBuilder ();
+ AddAttributes (sb, type);
+ AddTypeQualifiers (sb, type);
+ sb.AppendFormat ("{0} {1}", GetTypeKeyword(type), type.FullName);
+ return sb.ToString ();
+ }
+
+ protected void AddAttribute (StringBuilder sb, string attribute)
+ {
+ sb.AppendFormat ("{0}{1}{2}",
+ AttributeDelimeters[0], attribute, AttributeDelimeters[1]);
+ }
+
+ protected void AddAttributes (StringBuilder sb, MemberInfo m)
+ {
+ AddAttributes (sb, m, true);
+ }
+
+ protected void AddAttributes (StringBuilder sb, MemberInfo m, bool newline)
+ {
+ AddCilAttributes (sb, m, newline);
+ AddCustomAttributes (sb, m, "", newline);
+ }
+
+ private void AddCilAttributes (StringBuilder sb, MemberInfo m, bool newline)
+ {
+ Type t = m as Type;
+ MethodBase mb = m as MethodBase;
+ if (t != null)
+ AddCilAttributes (sb, t, newline);
+ else if (mb != null)
+ AddCilAttributes (sb, mb, newline);
+ }
+
+ private void AddCilAttributes (StringBuilder sb, Type t, bool newline)
+ {
+ if (t.IsSerializable) {
+ AddAttribute (sb, "Serializable");
+ if (newline)
+ sb.Append ("\n");
+ }
+ }
+
+ private void AddCilAttributes (StringBuilder sb, MethodBase m, bool newline)
+ {
+ MethodImplAttributes attr = m.GetMethodImplementationFlags ();
+ if ((attr & MethodImplAttributes.InternalCall) != 0) {
+ AddAttribute (sb, "MethodImplAttribute(MethodImplOptions.InternalCall)");
+ if (newline)
+ sb.Append ("\n");
+ }
+ }
+
+ protected void AddTypeQualifiers (StringBuilder sb, Type type)
+ {
+ if (type.IsPublic)
+ sb.Append (QualifierPublic + " ");
+ if (type.IsSealed && !type.IsValueType)
+ sb.Append (QualifierFinal + " ");
+ if (type.IsAbstract && !type.IsInterface)
+ sb.Append (QualifierAbstract + " ");
+ }
+
+ new protected string GetTypeKeyword (Type type)
+ {
+ if (type.IsClass)
+ return KeywordClass;
+ if (type.IsEnum)
+ return KeywordEnum;
+ if (type.IsValueType)
+ return KeywordValueType;
+ if (type.IsInterface)
+ return KeywordInterface;
+
+ // unknown type
+ return "type";
}
protected override string GetBaseTypeDescription (Type type, object instance)
{
- return type.Name;
+ if (type != null)
+ return string.Format ("{0} {1}", KeywordInherits, type.Name);
+ return string.Format ("{0} No Base Type", LineComment);
}
protected override string GetInterfaceDescription (Type type, object instance)
{
- return type.Name;
+ return string.Format ("{0} {1}", KeywordImplements, type.Name);
}
protected override string GetConstructorDescription (ConstructorInfo ctor, object instance)
{
- return string.Format ("{0} ({1})", ctor.Name, ctor.GetParameters().Length);
- // return ctor.Name;
+ StringBuilder sb = new StringBuilder ();
+ AddAttributes (sb, ctor);
+ AddMethodQualifiers (sb, ctor);
+ sb.AppendFormat ("{0} ", GetConstructorName (ctor));
+ AddMethodArgs (sb, ctor);
+
+ return sb.ToString();
+ }
+
+ protected void AddMethodQualifiers (StringBuilder sb, MethodBase m)
+ {
+ if (m.IsPublic)
+ sb.AppendFormat ("{0} ", QualifierPublic);
+ if (m.IsFamily)
+ sb.AppendFormat ("{0} ", QualifierFamily);
+ if (m.IsAssembly)
+ sb.AppendFormat ("{0} ", QualifierAssembly);
+ if (m.IsPrivate)
+ sb.AppendFormat ("{0} ", QualifierPrivate);
+ if (m.IsStatic)
+ sb.AppendFormat ("{0} ", QualifierStatic);
+ if (m.IsFinal)
+ sb.AppendFormat ("{0} ", QualifierFinal);
+ if (m.IsAbstract)
+ sb.AppendFormat ("{0} ", QualifierAbstract);
+ else if (m.IsVirtual)
+ sb.AppendFormat ("{0} ", QualifierVirtual);
+ }
+
+ protected abstract string GetConstructorName (ConstructorInfo ctor);
+
+ protected void AddMethodArgs (StringBuilder sb, MethodBase m)
+ {
+ sb.Append ("(");
+ ParameterInfo[] parms = m.GetParameters ();
+ if (parms.Length != 0) {
+ int cur = 0;
+ foreach (ParameterInfo pi in parms) {
+ sb.Append (GetParameterDescription (pi, pi));
+ if (cur++ != (parms.Length-1))
+ sb.Append (", ");
+ }
+ }
+ sb.Append (")");
}
protected override string GetEventDescription (EventInfo e, object instance)
{
- return e.Name;
+ StringBuilder sb = new StringBuilder ();
+ AddMethodQualifiers (sb, e.GetAddMethod(true));
+ return string.Format ("{0}{1}{2} {3}",
+ sb.ToString (),
+ e.IsMulticast ? KeywordMulticast + " " : "",
+ e.EventHandlerType,
+ e.Name);
}
protected override string GetFieldDescription (FieldInfo field, object instance)
{
+ StringBuilder sb = new StringBuilder ();
+ AddAttributes (sb, field);
+
+ if (!field.DeclaringType.IsEnum || field.IsSpecialName) {
+ AddFieldQualifiers (sb, field);
+ sb.AppendFormat ("{0} ", field.FieldType);
+ }
+
+ sb.Append (field.Name);
+
try {
- return string.Format ("{0}={1}", field.Name,
- // GetValue (field, instance));
- GetValue (instance));
- } catch {
- return field.Name;
+ sb.AppendFormat (" = {0}", GetValue (field.GetValue (instance)));
+ }
+ catch {
}
+
+ if (!field.DeclaringType.IsEnum || field.IsSpecialName)
+ sb.Append (KeywordStatementTerminator);
+ else
+ sb.Append (KeywordStatementSeparator);
+
+ return sb.ToString();
}
- protected override string GetMethodDescription (MethodInfo mb, object instance)
+ protected void AddFieldQualifiers (StringBuilder sb, FieldInfo field)
{
- if (mb.GetParameters().Length == 0) {
+ if (field.IsPublic)
+ sb.AppendFormat ("{0} ", QualifierPublic);
+ if (field.IsPrivate)
+ sb.AppendFormat ("{0} ", QualifierPrivate);
+ if (field.IsAssembly)
+ sb.AppendFormat ("{0} ", QualifierAssembly);
+ if (field.IsFamily)
+ sb.AppendFormat ("{0} ", QualifierFamily);
+ if (field.IsLiteral)
+ sb.AppendFormat ("{0} ", QualifierLiteral);
+ else if (field.IsStatic)
+ sb.AppendFormat ("{0} ", QualifierStatic);
+ }
+
+ protected override string GetMethodDescription (MethodInfo method, object instance)
+ {
+ StringBuilder sb = new StringBuilder ();
+
+ if (method.IsSpecialName)
+ sb.AppendFormat ("{0} Method is a specially named method:\n", LineComment);
+
+ AddAttributes (sb, method);
+ if (method.ReturnTypeCustomAttributes != null)
+ AddCustomAttributes (sb, method.ReturnTypeCustomAttributes, "return: ", true);
+
+ AddMethodQualifiers (sb, method);
+
+ AddMethodDeclaration (sb, method);
+
+ if (method.GetParameters().Length == 0) {
try {
- object r = mb.Invoke (instance, null);
+ object r = method.Invoke (instance, null);
string s = GetValue (r);
- return string.Format ("{0}()={1}", mb.Name, s);
+ sb.AppendFormat (" {0} = {1}", LineComment, s);
}
catch {
}
}
- return string.Format ("{0} ({1})", mb.Name, mb.GetParameters().Length);
+
+ string r = sb.ToString();
+
+ if (method.IsSpecialName)
+ return r.Replace ("\n", "\n" + LineComment + "\t");
+ return r;
+ }
+
+ protected virtual void AddMethodDeclaration (StringBuilder sb, MethodInfo method)
+ {
+ sb.AppendFormat ("{0} {1} ", method.ReturnType, method.Name);
+
+ AddMethodArgs (sb, method);
}
protected override string GetParameterDescription (ParameterInfo param, object instance)
{
- return param.Name;
+ StringBuilder sb = new StringBuilder ();
+
+ AddCustomAttributes (sb, param, "", false);
+ AddParameterAttributes (sb, param.Attributes);
+
+ sb.AppendFormat ("{0} {1}", param.ParameterType, param.Name);
+
+ return sb.ToString();
}
- protected override string GetPropertyDescription (PropertyInfo property, object instance)
+ protected void AddParameterAttributes (StringBuilder sb, ParameterAttributes attrs)
{
- string v = "";
- try {
- // object o = property.GetGetMethod(true).Invoke(instance, null);
- object o = property.GetValue (instance, null);
- v = string.Format ("={0}", GetValue (o));
- } catch {
- v = "";
- }
- return string.Format ("{0}{1}", property.Name, v);
- // return property.Name;
- // return string.Format ("{0}={1}", property.Name, property.GetValue(null));
+ if ((attrs & ParameterAttributes.In) != 0)
+ sb.Append ("in");
+ if ((attrs & ParameterAttributes.Out) != 0)
+ sb.Append ("out");
+ if ((attrs & ParameterAttributes.Lcid) != 0)
+ sb.Append ("lcid");
+ if ((attrs & ParameterAttributes.Retval) != 0)
+ sb.Append ("retval");
+ if ((attrs & ParameterAttributes.Optional) != 0)
+ sb.Append ("optional");
+ if ((attrs & ParameterAttributes.HasDefault) != 0)
+ sb.Append ("hasdefault");
+ if ((attrs & ParameterAttributes.HasFieldMarshal) != 0)
+ sb.Append ("hasfieldmarshal");
+ if ((attrs & ParameterAttributes.ReservedMask) != 0)
+ sb.Append ("reservedmask");
+ if ((attrs & ParameterAttributes.Reserved3) != 0)
+ sb.Append ("reserved3");
+ if ((attrs & ParameterAttributes.Reserved4) != 0)
+ sb.Append ("reserved4");
}
- protected override string GetCustomAttributeProviderDescription (ICustomAttributeProvider m, object instance)
+ protected override string GetPropertyDescription (PropertyInfo property, object instance)
{
StringBuilder sb = new StringBuilder ();
- foreach (object a in m.GetCustomAttributes(true)) {
- sb.Append (string.Format ("\n\t{0}", GetCustomAttribute(a)));
+ AddAttributes (sb, property);
+ AddMethodQualifiers (sb, property.GetAccessors(true)[0]);
+
+ sb.AppendFormat ("{0} {1} {{", property.PropertyType, property.Name);
+ if (property.CanRead) {
+ sb.Append ("get");
+ try {
+ sb.AppendFormat (" /* = {0} */", GetValue (property.GetValue (instance, null)));
+ }
+ catch {
+ }
+ sb.Append (";");
}
- return string.Format ("GetCustomAttributes()={0}{1}",
- sb.Length == 0 ? "<none/>" : "",
- sb.ToString());
+ if (property.CanWrite)
+ sb.Append ("set;");
+ sb.Append ("}}");
+
+ return sb.ToString();
}
- protected override string GetCustomAttributes (ICustomAttributeProvider m, string attributeType, bool newLine)
+ protected override string GetReturnValueDescription (NodeInfo n)
{
- StringBuilder sb = new StringBuilder ();
+ return string.Format ("{0} ReturnValue={1}",
+ LineComment, GetOtherDescription (n));
+ }
+
+ protected override string GetOtherDescription (NodeInfo node)
+ {
+ if (node.Description != null)
+ return node.Description.ToString();
+ return "<null other description/>";
+ }
+ protected void AddCustomAttributes (StringBuilder sb, ICustomAttributeProvider m, string attributeType, bool newLine)
+ {
object[] attrs = m.GetCustomAttributes (true);
foreach (object a in attrs) {
- GetCustomAttribute (sb, a, attributeType);
+ AddCustomAttribute (sb, a, attributeType);
if (newLine)
sb.Append ("\n");
}
-
- return sb.ToString ();
}
- protected override string GetCustomAttribute (object attribute)
- {
- StringBuilder sb = new StringBuilder ();
- GetCustomAttribute (sb, attribute, "");
- return sb.ToString();
- }
-
- protected override void GetCustomAttribute (StringBuilder sb, object attribute, string attributeType)
+ protected virtual void AddCustomAttribute (StringBuilder sb, object attribute, string attributeType)
{
Type type = attribute.GetType();
- char[] delims = GetAttributeDelimeters ();
- sb.AppendFormat ("{0}{1}{2}", delims[0], attributeType, type.FullName);
+ sb.AppendFormat ("{0}{1}{2}", AttributeDelimeters[0], attributeType, type.FullName);
- string p = GetPropertyValues (type.GetProperties(), attribute);
- string f = GetFieldValues (type.GetFields(), attribute);
+ PropertyInfo[] props = type.GetProperties();
+ FieldInfo[] fields = type.GetFields();
- if ((p.Length > 0) || (f.Length > 0)) {
+ if (props.Length > 0 || fields.Length > 0) {
sb.Append ("(");
- if (p.Length > 0) {
- sb.Append (p);
- if (f.Length > 0)
+ if (props.Length > 0) {
+ AddPropertyValues (sb, props, attribute);
+ if (fields.Length > 0)
sb.Append (", ");
}
- if (f.Length > 0)
- sb.Append (f);
+ if (fields.Length > 0)
+ AddFieldValues (sb, fields, attribute);
sb.Append (")");
}
-
- sb.Append (delims[1]);
+ sb.Append (AttributeDelimeters[1]);
}
- protected override char[] GetAttributeDelimeters ()
- {
- return new char[]{'[', ']'};
- }
-
- private string GetPropertyValues (PropertyInfo[] props, object instance)
+ private void AddPropertyValues (StringBuilder sb, PropertyInfo[] props, object instance)
{
int len = props.Length;
- StringBuilder sb = new StringBuilder ();
for (int i = 0; i != len; ++i) {
sb.Append (props[i].Name);
sb.Append ("=");
if (i != (len-1))
sb.Append (", ");
}
- return sb.ToString();
}
- private string GetFieldValues (FieldInfo[] fields, object instance)
+ private void AddFieldValues (StringBuilder sb, FieldInfo[] fields, object instance)
{
int len = fields.Length;
- StringBuilder sb = new StringBuilder ();
for (int i = 0; i != len; ++i) {
sb.Append (fields[i].Name);
sb.Append ("=");
if (i != (len-1))
sb.Append (", ");
}
- return sb.ToString();
}
- protected override string GetEncodedValue (object value)
+ protected virtual string GetEncodedValue (object value)
{
if (value == null)
return "null";
return value.ToString();
}
- protected override string GetEncodedCharValue (object value)
+ protected virtual string GetEncodedCharValue (object value)
{
return String.Format ("'{0}'", value.ToString());
}
- protected override string GetEncodedDecimalValue (object value)
+ protected virtual string GetEncodedDecimalValue (object value)
{
return String.Format ("{0}m", value.ToString());
}
- protected override string GetEncodedDoubleValue (object value)
+ protected virtual string GetEncodedDoubleValue (object value)
{
return String.Format ("{0}d", value.ToString());
}
- protected override string GetEncodedInt64Value (object value)
+ protected virtual string GetEncodedInt64Value (object value)
{
return String.Format ("{0}L", value.ToString());
}
- protected override string GetEncodedSingleValue (object value)
+ protected virtual string GetEncodedSingleValue (object value)
{
return String.Format ("{0}f", value.ToString());
}
- protected override string GetEncodedStringValue (object value)
+ protected virtual string GetEncodedStringValue (object value)
{
return String.Format ("\"{0}\"", value.ToString());
}
- protected override string GetEncodedUInt32Value (object value)
+ protected virtual string GetEncodedUInt32Value (object value)
{
return String.Format ("{0}U", value.ToString());
}
- protected override string GetEncodedUInt64Value (object value)
+ protected virtual string GetEncodedUInt64Value (object value)
{
return String.Format ("{0}UL", value.ToString());
}
- protected override string GetEncodedObjectValue (object value)
+ protected virtual string GetEncodedObjectValue (object value)
{
return String.Format ("typeof({0})", value.ToString());
}
-
- protected override string GetOtherDescription (NodeInfo node)
- {
- if (node.Description != null)
- return node.Description.ToString();
- return "<null other description/>";
- }
}
}
CSC = csc
-TRACE_ARGS = /out:$(PROGRAM) /d:TRACE /d:DEBUG
-
-# CSCFLAGS = $(TRACE_ARGS) /debug+ /debug:full
-CSCFLAGS = $(TRACE_ARGS)
-
-PROGRAM = type-reflector.exe
-
-MONO = mono
-
-PROGRAM_FILES = \
- ConsoleOutput.cs \
- CSharpNodeFormatter.cs \
- DefaultNodeFormatter.cs \
- ExplicitNodeFinder.cs \
- Factories.cs \
- GroupingNodeFinder.cs \
- IndentingTextWriter.cs \
- INodeFinder.cs \
- INodeFormatter.cs \
- LanguageNodeFormatter.cs \
- Node.cs \
- NodeFinder.cs \
- NodeFormatter.cs \
- NodeGrouper.cs \
- NodeInfo.cs \
- NodeTypes.cs \
- ProgramOptions.cs \
- ReflectionNodeFinder.cs \
- TestTypes.cs \
- TextFormatter.cs \
- TypeLoader.cs \
- TypeFactory.cs \
- TypeReflectorOptions.cs \
-
-all: $(PROGRAM)
-
-$(PROGRAM) : $(PROGRAM_FILES)
- $(CSC) $(CSCFLAGS) $(PROGRAM_FILES)
-
-test-run : $(PROGRAM)
- $(MONO) $(PROGRAM) -A $(PROGRAM) $(ARGS)
-
-test-type : $(PROGRAM)
- $(MONO) $(PROGRAM) -A $(PROGRAM) --max-depth=10000 $(ARGS) TestClass$$
-
-run : $(PROGRAM)
- $(MONO) $(PROGRAM) $(ARGS)
-
-windows:
- NAnt -buildfile:type-reflector.build
-
-linux:
- mcs @unix.args
-
-clean:
- rm -f *.exe *.pdb *.dll *.dbg *~
-
-linecount:
- wc -l $(PROGRAM_FILES)
+include makefile.core
get {return nodeInfo;}
set {nodeInfo = value;}
}
-
- /*
- public override string ToString ()
- {
- Console.Write ("(Description='{0}'", Description);
- if (Children.Count > 0) {
- Console.Write (" Children={{");
- foreach (Node node in Children)
- Console.Write (node);
- Console.Write ("}}");
- }
- Console.Write (")");
- return "foo!";
- return new StackTrace().ToString();
- }
- */
}
public class NodeCollection : CollectionBase {
private bool verboseOutput = false;
private bool showMonoBroken = false;
- // `ReflectionTypeDisplayer.PrintTypeProperties' is recursive, but refrains
- // from printing duplicates. Despite duplicate removal, the output for
- // printing the Properties of System.Type is > 800K of text.
- //
- // 3 levels permits viewing Attribute values, but not the attributes of
- // those attribute values.
- //
- // For example, 3 levels permits:
- // class System.Type {depth 0}
- // Properties: {depth 1}
- // System.Reflection.MemberTypes MemberType {depth 2}
- // - CanRead=True {depth 3}
- // - CanWrite=False {depth 3}
- // ...
- private int maxDepth = 3;
-
- public int MaxDepth {
- get {return maxDepth;}
- set {maxDepth = value;}
- }
-
public bool ShowBase {
get {return showBase;}
set {showBase = value;}
// always handle NodeTypes.Type
if (root.NodeType == NodeTypes.Type)
- GetTypeChildren (c, root, (Type) root.ReflectionObject);
+ AddTypeChildren (c, root, (Type) root.ReflectionObject);
else if (VerboseOutput) {
switch (root.NodeType) {
case NodeTypes.BaseType:
- GetBaseTypeChildren (c, root, (Type) root.ReflectionObject);
+ AddBaseTypeChildren (c, root, (Type) root.ReflectionObject);
break;
case NodeTypes.Interface:
- GetInterfaceChildren (c, root, (Type) root.ReflectionObject);
+ AddInterfaceChildren (c, root, (Type) root.ReflectionObject);
break;
case NodeTypes.Field:
- GetFieldChildren (c, root, (FieldInfo) root.ReflectionObject);
+ AddFieldChildren (c, root, (FieldInfo) root.ReflectionObject);
break;
case NodeTypes.Constructor:
- GetConstructorChildren (c, root, (ConstructorInfo) root.ReflectionObject);
+ AddConstructorChildren (c, root, (ConstructorInfo) root.ReflectionObject);
break;
case NodeTypes.Method:
- GetMethodChildren (c, root, (MethodInfo) root.ReflectionObject);
+ AddMethodChildren (c, root, (MethodInfo) root.ReflectionObject);
break;
case NodeTypes.Parameter:
- GetParameterChildren (c, root, (ParameterInfo) root.ReflectionObject);
+ AddParameterChildren (c, root, (ParameterInfo) root.ReflectionObject);
break;
case NodeTypes.Property:
- GetPropertyChildren (c, root, (PropertyInfo) root.ReflectionObject);
+ AddPropertyChildren (c, root, (PropertyInfo) root.ReflectionObject);
break;
case NodeTypes.Event:
- GetEventChildren (c, root, (EventInfo) root.ReflectionObject);
+ AddEventChildren (c, root, (EventInfo) root.ReflectionObject);
break;
case NodeTypes.ReturnValue:
- GetReturnValueChildren (c, root);
+ AddReturnValueChildren (c, root);
break;
case NodeTypes.Other:
case NodeTypes.Alias:
- GetOtherChildren (c, root);
+ AddOtherChildren (c, root);
break;
default:
- GetUnhandledChildren (c, root);
+ AddUnhandledChildren (c, root);
break;
}
}
return c;
}
- protected virtual void GetTypeChildren (NodeInfoCollection c, NodeInfo root, Type type)
+ protected virtual void AddTypeChildren (NodeInfoCollection c, NodeInfo root, Type type)
{
}
- protected virtual void GetBaseTypeChildren (NodeInfoCollection c, NodeInfo root, Type baseType)
+ protected virtual void AddBaseTypeChildren (NodeInfoCollection c, NodeInfo root, Type baseType)
{
}
- protected virtual void GetInterfaceChildren (NodeInfoCollection c, NodeInfo root, Type iface)
+ protected virtual void AddInterfaceChildren (NodeInfoCollection c, NodeInfo root, Type iface)
{
}
- protected virtual void GetFieldChildren (NodeInfoCollection c, NodeInfo root, FieldInfo field)
+ protected virtual void AddFieldChildren (NodeInfoCollection c, NodeInfo root, FieldInfo field)
{
- Console.WriteLine ("** field children b");
}
- protected virtual void GetConstructorChildren (NodeInfoCollection c, NodeInfo root, ConstructorInfo ctor)
+ protected virtual void AddConstructorChildren (NodeInfoCollection c, NodeInfo root, ConstructorInfo ctor)
{
}
- protected virtual void GetMethodChildren (NodeInfoCollection c, NodeInfo root, MethodInfo method)
+ protected virtual void AddMethodChildren (NodeInfoCollection c, NodeInfo root, MethodInfo method)
{
}
- protected virtual void GetParameterChildren (NodeInfoCollection c, NodeInfo root, ParameterInfo param)
+ protected virtual void AddParameterChildren (NodeInfoCollection c, NodeInfo root, ParameterInfo param)
{
}
- protected virtual void GetPropertyChildren (NodeInfoCollection c, NodeInfo root, PropertyInfo property)
+ protected virtual void AddPropertyChildren (NodeInfoCollection c, NodeInfo root, PropertyInfo property)
{
}
- protected virtual void GetEventChildren (NodeInfoCollection c, NodeInfo root, EventInfo e)
+ protected virtual void AddEventChildren (NodeInfoCollection c, NodeInfo root, EventInfo e)
{
}
- protected virtual void GetReturnValueChildren (NodeInfoCollection c, NodeInfo root)
+ protected virtual void AddReturnValueChildren (NodeInfoCollection c, NodeInfo root)
{
if (root.ReflectionObject != null)
- GetTypeChildren (c, root, (Type) root.ReflectionObject);
+ AddTypeChildren (c, root, (Type) root.ReflectionObject);
}
- protected virtual void GetOtherChildren (NodeInfoCollection c, NodeInfo root)
+ protected virtual void AddOtherChildren (NodeInfoCollection c, NodeInfo root)
{
if (root.Description is NodeGroup) {
NodeGroup g = (NodeGroup) root.Description;
}
}
- protected virtual void GetUnhandledChildren (NodeInfoCollection c, NodeInfo root)
+ protected virtual void AddUnhandledChildren (NodeInfoCollection c, NodeInfo root)
{
c.Add (new NodeInfo (root, "Unhandled child: NodeType=" + root.NodeType));
}
case NodeTypes.Event:
r = GetEventDescription ((EventInfo) node.ReflectionObject, node.ReflectionInstance);
break;
+ /*
case NodeTypes.CustomAttributeProvider:
r = GetCustomAttributeProviderDescription ((ICustomAttributeProvider) node.ReflectionObject, node.ReflectionInstance);
break;
+ */
case NodeTypes.Other:
case NodeTypes.Alias:
r = GetOtherDescription (node);
protected virtual string GetTypeDescription (Type type, object instance)
{
- return string.Format ("{0} {1}", GetTypeKeyword(type), type.FullName);
+ return string.Format ("{0} {1}",
+ GetTypeKeyword(type), type.FullName);
}
protected virtual string GetBaseTypeDescription (Type type, object instance)
{
- return type.Name;
+ if (type != null)
+ return type.Name;
+ return "No Base Type";
}
protected virtual string GetInterfaceDescription (Type type, object instance)
return property.Name;
}
- protected virtual string GetCustomAttributeProviderDescription (ICustomAttributeProvider m, object instance)
- {
- StringBuilder sb = new StringBuilder ();
- foreach (object a in m.GetCustomAttributes(true)) {
- sb.Append (string.Format ("\n\t{0}", GetCustomAttribute(a)));
- }
- return string.Format ("GetCustomAttributes()={0}{1}",
- sb.Length == 0 ? "<none/>" : "",
- sb.ToString());
- }
-
- protected virtual string GetCustomAttributes (ICustomAttributeProvider m, string attributeType, bool newLine)
- {
- StringBuilder sb = new StringBuilder ();
-
- object[] attrs = m.GetCustomAttributes (true);
-
- foreach (object a in attrs) {
-
- GetCustomAttribute (sb, a, attributeType);
-
- if (newLine)
- sb.Append ("\n");
- }
-
- return sb.ToString ();
- }
-
- protected virtual string GetCustomAttribute (object attribute)
- {
- StringBuilder sb = new StringBuilder ();
- GetCustomAttribute (sb, attribute, "");
- return sb.ToString();
- }
-
- protected virtual void GetCustomAttribute (StringBuilder sb, object attribute, string attributeType)
- {
- Type type = attribute.GetType();
- char[] delims = GetAttributeDelimeters ();
- sb.AppendFormat ("{0}{1}{2}", delims[0], attributeType, type.FullName);
-
- string p = GetPropertyValues (type.GetProperties(), attribute);
- string f = GetFieldValues (type.GetFields(), attribute);
-
- if ((p.Length > 0) || (f.Length > 0)) {
- sb.Append ("(");
- if (p.Length > 0) {
- sb.Append (p);
- if (f.Length > 0)
- sb.Append (", ");
- }
- if (f.Length > 0)
- sb.Append (f);
- sb.Append (")");
- }
-
- sb.Append (delims[1]);
- }
-
- protected virtual char[] GetAttributeDelimeters ()
- {
- return new char[]{'[', ']'};
- }
-
- private string GetPropertyValues (PropertyInfo[] props, object instance)
- {
- int len = props.Length;
- StringBuilder sb = new StringBuilder ();
- for (int i = 0; i != len; ++i) {
- sb.Append (props[i].Name);
- sb.Append ("=");
- try {
- sb.Append (GetEncodedValue (props[i].GetValue (instance, null)));
- } catch {
- sb.Append ("<exception/>");
- }
- if (i != (len-1))
- sb.Append (", ");
- }
- return sb.ToString();
- }
-
- private string GetFieldValues (FieldInfo[] fields, object instance)
- {
- int len = fields.Length;
- StringBuilder sb = new StringBuilder ();
- for (int i = 0; i != len; ++i) {
- sb.Append (fields[i].Name);
- sb.Append ("=");
- sb.Append (GetEncodedValue (fields[i].GetValue (instance)));
- if (i != (len-1))
- sb.Append (", ");
- }
- return sb.ToString();
- }
-
- protected virtual string GetEncodedValue (object value)
- {
- if (value == null)
- return "null";
-
- switch (Type.GetTypeCode(value.GetType())) {
- case TypeCode.Char:
- return GetEncodedCharValue (value);
- case TypeCode.Decimal:
- return GetEncodedDecimalValue (value);
- case TypeCode.Double:
- return GetEncodedDoubleValue (value);
- case TypeCode.Int64:
- return GetEncodedInt64Value (value);
- case TypeCode.Single:
- return GetEncodedSingleValue (value);
- case TypeCode.String:
- return GetEncodedStringValue (value);
- case TypeCode.UInt32:
- return GetEncodedUInt32Value (value);
- case TypeCode.UInt64:
- return GetEncodedUInt64Value (value);
- case TypeCode.Object:
- return GetEncodedObjectValue (value);
- }
- // not special-cased; just return it's value
- return value.ToString();
- }
-
- protected virtual string GetEncodedCharValue (object value)
- {
- return String.Format ("'{0}'", value.ToString());
- }
-
- protected virtual string GetEncodedDecimalValue (object value)
- {
- return String.Format ("{0}m", value.ToString());
- }
-
- protected virtual string GetEncodedDoubleValue (object value)
- {
- return String.Format ("{0}d", value.ToString());
- }
-
- protected virtual string GetEncodedInt64Value (object value)
- {
- return String.Format ("{0}L", value.ToString());
- }
-
- protected virtual string GetEncodedSingleValue (object value)
- {
- return String.Format ("{0}f", value.ToString());
- }
-
- protected virtual string GetEncodedStringValue (object value)
- {
- return String.Format ("\"{0}\"", value.ToString());
- }
-
- protected virtual string GetEncodedUInt32Value (object value)
- {
- return String.Format ("{0}U", value.ToString());
- }
-
- protected virtual string GetEncodedUInt64Value (object value)
- {
- return String.Format ("{0}UL", value.ToString());
- }
-
- protected virtual string GetEncodedObjectValue (object value)
- {
- return String.Format ("typeof({0})", value.ToString());
- }
-
protected virtual string GetOtherDescription (NodeInfo node)
{
if (node.Description != null)
get {return description;}
set {description = value;}
}
+
+ /*
+ public override string ToString ()
+ {
+ Console.WriteLine ("** (NodeInfo (parent {0}) (type {1}) (rObj {2}) (rIns {3}) (description {4}))",
+ parent, type, reflectionObject, reflectionInstance, description);
+ return base.ToString ();
+ }
+ */
}
public sealed class NodeInfoCollection : CollectionBase {
namespace Mono.TypeReflector
{
- internal class OptionException : Exception {
+ public class OptionException : Exception {
public char ShortForm;
}
}
- internal class ProgramOptions {
+ public class ProgramOptions {
private class Option {
public char ShortForm = '\0';
+Overview
+========
``type-reflector'' is a program similar in spirit to the .NET ``TypeFinder''
SDK Sample. As is often the case with Unix-style programs, it has more
program options and more flexibility.
displayed. There are currently two such policies:
default - typically the result of .ToString() on the member reflection object
csharp - attempts to display the member as if it were from C# source code.
+ vb - attempts to display the member as if it were from VB.NET source code.
Finally, it shows (virtually) everything about a type that is available
through the System.Reflection facility. Everthing from the actual Attributes
normally present without writing test programs to view the available
information.
+GUI Support
+===========
+type-reflector has a prototype GUI using Gtk#. To compile it, run:
+
+ make -f makefile.gnu gui
+
+To run it, pass ``--displayer=gtk'' on the command line:
+
+ type-reflector.exe --displayer-gtk .
+
private static readonly IComparer NameComparer = new MemberInfoNameComparer ();
- protected override void GetTypeChildren (NodeInfoCollection c, NodeInfo parent, Type type)
+ protected override void AddTypeChildren (NodeInfoCollection c, NodeInfo parent, Type type)
{
foreach (MemberInfo mi in GetMembers (type)) {
AddNode (c, parent, mi, mi);
}
}
- protected override void GetFieldChildren (NodeInfoCollection c, NodeInfo parent, FieldInfo field)
+ protected override void AddFieldChildren (NodeInfoCollection c, NodeInfo parent, FieldInfo field)
{
AddSubnodes (c, parent, field.GetType(), field);
}
- protected override void GetConstructorChildren (NodeInfoCollection c, NodeInfo parent, ConstructorInfo ctor)
+ protected override void AddConstructorChildren (NodeInfoCollection c, NodeInfo parent, ConstructorInfo ctor)
{
GetMethodBaseChildren (c, parent, ctor);
}
- protected override void GetMethodChildren (NodeInfoCollection c, NodeInfo parent, MethodInfo method)
+ protected override void AddMethodChildren (NodeInfoCollection c, NodeInfo parent, MethodInfo method)
{
GetMethodBaseChildren (c, parent, method);
}
AddSubnodes (c, parent, mb.GetType(), mb);
}
- protected override void GetParameterChildren (NodeInfoCollection c, NodeInfo parent, ParameterInfo param)
+ protected override void AddParameterChildren (NodeInfoCollection c, NodeInfo parent, ParameterInfo param)
{
AddSubnodes (c, parent, param.GetType(), param);
}
- protected override void GetPropertyChildren (NodeInfoCollection c, NodeInfo parent, PropertyInfo pi)
+ protected override void AddPropertyChildren (NodeInfoCollection c, NodeInfo parent, PropertyInfo pi)
{
AddSubnodes (c, parent, pi.GetType(), pi);
}
- protected override void GetEventChildren (NodeInfoCollection c, NodeInfo parent, EventInfo e)
+ protected override void AddEventChildren (NodeInfoCollection c, NodeInfo parent, EventInfo e)
{
AddSubnodes (c, parent, e.GetType(), e);
}
- protected override void GetReturnValueChildren (NodeInfoCollection c, NodeInfo parent)
+ protected override void AddReturnValueChildren (NodeInfoCollection c, NodeInfo parent)
{
if (parent.ReflectionObject != null)
- GetTypeChildren (c, parent, (Type) parent.ReflectionObject);
+ AddTypeChildren (c, parent, (Type) parent.ReflectionObject);
}
}
}
{
public interface IFoo {}
public interface IBar {}
- public interface IBaz {}
+ public interface IBaz : IFoo, IBar {}
public delegate void FooEventHandler ();
--- /dev/null
+//
+// TypeDisplayer.cs:
+// Common ITypeDisplayer operations
+//
+// Author: Jonathan Pryor (jonpryor@vt.edu)
+//
+// (C) 2002 Jonathan Pryor
+//
+
+// #define TRACE
+
+using System;
+using System.Collections;
+using System.IO;
+using System.Diagnostics;
+using System.Reflection;
+using System.Text;
+using System.Text.RegularExpressions;
+
+namespace Mono.TypeReflector
+{
+ sealed class DisplayerComparer : IComparer
+ {
+ public static readonly DisplayerComparer Default;
+
+ static DisplayerComparer ()
+ {
+ Default = new DisplayerComparer ();
+ }
+
+ // we store either Assembly's or strings; handle both.
+ public int Compare (object a, object b)
+ {
+ if (a is Assembly) {
+ Assembly aa = (Assembly) a;
+ Assembly ab = (Assembly) b;
+ return aa.FullName.CompareTo (ab.FullName);
+ }
+ if (a is Type) {
+ Type ta = (Type) a;
+ Type tb = (Type) b;
+ return ta.FullName.CompareTo (tb.FullName);
+ }
+ return Comparer.Default.Compare (a, b);
+ }
+ }
+
+ public abstract class TypeDisplayer : ITypeDisplayer
+ {
+ private INodeFormatter formatter;
+ private INodeFinder finder;
+ private TypeReflectorOptions options;
+
+ // type: map<Assembly, map<Namespace, list<Type> > >
+ private IDictionary types = CreateDictionary ();
+
+ public TypeDisplayer ()
+ {
+ }
+
+ public INodeFormatter Formatter {
+ get {return formatter;}
+ set {formatter = value;}
+ }
+
+ public INodeFinder Finder {
+ get {return finder;}
+ set {finder = value;}
+ }
+
+ public TypeReflectorOptions Options {
+ get {return options;}
+ set {options = value;}
+ }
+
+ public abstract int MaxDepth {set;}
+ public abstract bool RequireTypes {get;}
+
+ protected ICollection Assemblies {
+ get {return types.Keys;}
+ }
+
+ private static IDictionary CreateDictionary ()
+ {
+ return new SortedList (DisplayerComparer.Default);
+ }
+
+ protected ICollection Namespaces (Assembly a)
+ {
+ return _Namespaces(a).Keys;
+ }
+
+ protected ICollection Types (Assembly a, string ns)
+ {
+ // return (ICollection) _Namespaces(a)[ns];
+ return _Types (_Namespaces(a), ns).Keys;
+ }
+
+ private IDictionary _Namespaces (Assembly a)
+ {
+ IDictionary d = (IDictionary) types[a];
+ if (d == null) {
+ d = CreateDictionary ();
+ types[a] = d;
+ }
+ return d;
+ }
+
+ private IDictionary _Types (IDictionary namespaces, string ns)
+ {
+ IDictionary list = (IDictionary) namespaces[ns];
+ if (list == null) {
+ list = CreateDictionary ();
+ namespaces[ns] = list;
+ }
+ return list;
+ }
+
+ public virtual void AddType (Type type)
+ {
+ _Types(_Namespaces(type.Assembly), type.Namespace)[type] = null;
+ }
+
+ public abstract void Run ();
+ }
+}
+
{
public class TypeFactory
{
+ private static BooleanSwitch info = new BooleanSwitch ("type-factory",
+ "Information about creating types.");
+
private IDictionary entries = new Hashtable ();
public void Add (object key, Type value)
public object Create (object key)
{
+ Type type = null;
try {
- Type type = (Type) entries[key];
+ type = (Type) entries[key];
return CreateInstance (type);
}
- catch {
+ catch (Exception e) {
+ Console.WriteLine ("TypeFactory trace: {0}", info.Enabled);
+ Console.WriteLine (
+ "Exception creating ({0}, {1}): {2}", key, type, e.ToString());
+ Trace.WriteLineIf (info.Enabled, string.Format (
+ "Exception creating ({0}, {1}): {2}", key, type, e.ToString()));
return null;
}
}
public TypeLoader (ICollection assemblies)
{
- Console.WriteLine ("type-loader: " + info.Level);
this.assemblies = assemblies;
}
set {assemblies = value;}
}
- public ICollection LoadTypes (string match)
+ public ICollection LoadTypes (IList match)
{
if (assemblies == null)
throw new ArgumentNullException ("Assemblies");
+ if (match == null || match.Count == 0)
+ throw new ArgumentNullException ("match");
+
+ StringBuilder regex = new StringBuilder ();
+ regex.Append (match[0]);
+ for (int i = 1; i < match.Count; ++i)
+ regex.AppendFormat ("|{0}", match[i]);
+
+ Regex re = new Regex (regex.ToString());
+
+ Trace.WriteLineIf (info.TraceInfo,
+ string.Format ("using regex: '{0}'", regex.ToString()));
IList found = new ArrayList ();
foreach (string a in assemblies) {
- LoadMatchingTypesFrom (a, match, found);
+ LoadMatchingTypesFrom (a, regex.ToString(), re, found);
}
return found;
}
- private void LoadMatchingTypesFrom (string where, string match, IList types)
+ private void LoadMatchingTypesFrom (string where, string regex, Regex re, IList types)
{
- Regex re = new Regex (match);
try {
Assembly a = Assembly.LoadFrom (where);
Type[] _types = a.GetTypes();
} catch (Exception e) {
Trace.WriteLineIf (info.TraceError, String.Format (
"Unable to load type regex `{0}' from `{1}'.",
- match, where));
+ regex, where));
Trace.WriteLineIf (info.TraceError, e.ToString());
}
}
f = c = b = rt = n = false;
if (MatchFullName)
f = r.Match(t.FullName).Success;
- if (MatchClassName)
+ else if (MatchClassName)
c = r.Match(t.Name).Success;
- if (MatchNamespace)
+ else if (MatchNamespace)
n = r.Match(t.Namespace).Success;
if (MatchBase) {
b = (!MatchFullName ? false : r.Match (t.BaseType.FullName).Success) ||
--- /dev/null
+//
+// TypeReflectorApp.cs:
+// Finds types and sends them to a displayer.
+//
+// Author: Jonathan Pryor (jonpryor@vt.edu)
+//
+// (C) 2002 Jonathan Pryor
+//
+
+// #define TRACE
+
+using System;
+using System.Collections;
+using System.IO;
+using System.Diagnostics;
+using System.Reflection;
+using System.Text;
+using System.Text.RegularExpressions;
+
+namespace Mono.TypeReflector
+{
+ public class TypeReflectorApp
+ {
+ private static BooleanSwitch console = new BooleanSwitch ("console",
+ "console-specific and command-line handling output");
+
+ private static void TraceStringArray (string message, IEnumerable contents)
+ {
+ Trace.WriteLineIf (console.Enabled, message);
+ foreach (string s in contents) {
+ Trace.WriteLineIf (console.Enabled, " " + s);
+ }
+ }
+
+ public static void PrintVersion ()
+ {
+ Console.WriteLine ("type-reflector 0.6");
+ Console.WriteLine ("Written by Jonathan Pryor.");
+ Console.WriteLine ();
+ Console.WriteLine ("Copyright (C) 2002 Jonathan Pryor.");
+ }
+
+ private static void InitFactory ()
+ {
+ Factories.Formatter.Add ("default", typeof (DefaultNodeFormatter));
+ Factories.Formatter.Add ("csharp", typeof (CSharpNodeFormatter));
+ Factories.Formatter.Add ("vb", typeof (VBNodeFormatter));
+ Factories.Finder.Add ("explicit", typeof (ExplicitNodeFinder));
+ Factories.Finder.Add ("reflection", typeof (ReflectionNodeFinder));
+ Factories.Displayer.Add ("console", typeof (ConsoleTypeDisplayer));
+#if HAVE_GUI_GTK
+ Factories.Displayer.Add ("gtk", typeof (GtkTypeDisplayer));
+#endif
+ }
+
+ public static void Main (string[] args)
+ {
+ InitFactory ();
+
+ TypeReflectorOptions options = new TypeReflectorOptions ();
+
+ bool quit = false;
+
+ try {
+ options.ParseOptions (args);
+ } catch (Exception e) {
+ Console.WriteLine (e.Message);
+ Console.WriteLine ("See `{0} --help' for more information", ProgramOptions.ProgramName);
+ // Console.WriteLine ("** Full Message continues:\n" + e);
+ return;
+ }
+
+ if (options.FoundHelp) {
+ Console.WriteLine (options.OptionsHelp);
+ quit = true;
+ }
+
+ if (options.DefaultAssemblies) {
+ Console.WriteLine ("The default search assemblies are:");
+ foreach (string s in TypeReflectorOptions.GetDefaultAssemblies ()) {
+ Console.WriteLine (" {0}", s);
+ }
+ quit = true;
+ }
+
+ if (options.Version) {
+ PrintVersion ();
+ quit = true;
+ }
+
+ if (quit)
+ return;
+
+ TraceStringArray ("Search Assemblies: ", options.Assemblies);
+ TraceStringArray ("Search for Types: ", options.Types);
+
+ TypeLoader loader = CreateLoader (options);
+
+ INodeFormatter formatter = CreateFormatter (options);
+ if (formatter == null) {
+ Console.WriteLine ("Error: invalid formatter: " + options.Formatter);
+ return;
+ }
+
+ INodeFinder finder = CreateFinder (options);
+ if (finder == null) {
+ Console.WriteLine ("Error: invalid finder: " + options.Finder);
+ return;
+ }
+
+ ITypeDisplayer displayer = CreateDisplayer (options);
+ if (displayer == null) {
+ Console.WriteLine ("Error: invalid displayer: " + options.Displayer);
+ return;
+ }
+
+ if (options.Types.Count == 0) {
+ Console.WriteLine ("No types specified.");
+ Console.WriteLine ("See `{0} --help' for more information", ProgramOptions.ProgramName);
+ return;
+ }
+
+ displayer.Finder = finder;
+ displayer.Formatter = formatter;
+ displayer.Options = options;
+
+ // Find the requested types and display them.
+ FindTypes (displayer, loader, options.Types);
+
+ displayer.Run ();
+ }
+
+ public static void FindTypes (ITypeDisplayer displayer, TypeLoader loader, IList types)
+ {
+ try {
+ ICollection typesFound = loader.LoadTypes (types);
+ if (typesFound.Count > 0)
+ foreach (Type type in typesFound) {
+ displayer.AddType (type);
+ }
+ else
+ Console.WriteLine ("Unable to find types.");
+ } catch (Exception e) {
+ Console.WriteLine ("Unable to display type: {0}.", e.ToString());
+ }
+ }
+
+ public static TypeLoader CreateLoader (TypeReflectorOptions options)
+ {
+ TypeLoader loader = new TypeLoader (options.Assemblies);
+ loader.MatchBase = options.MatchBase;
+ loader.MatchFullName = options.MatchFullName;
+ loader.MatchClassName = options.MatchClassName;
+ loader.MatchNamespace = options.MatchNamespace;
+ loader.MatchMethodReturnType = options.MatchReturnType;
+ return loader;
+ }
+
+ public static ITypeDisplayer CreateDisplayer (TypeReflectorOptions options)
+ {
+ ITypeDisplayer d = Factories.Displayer.Create (options.Displayer);
+ Console.WriteLine ("creating displayer: {0}", d);
+
+ if (d != null) {
+ d.MaxDepth = options.MaxDepth;
+ }
+
+ return d;
+ }
+
+ public static INodeFinder CreateFinder (TypeReflectorOptions options)
+ {
+ INodeFinder finder = Factories.Finder.Create (options.Finder);
+ NodeFinder f = finder as NodeFinder;
+
+ if (f != null) {
+ f.VerboseOutput = options.VerboseOutput;
+ f.ShowBase = options.ShowBase;
+ f.ShowConstructors = options.ShowConstructors;
+ f.ShowEvents = options.ShowEvents;
+ f.ShowFields = options.ShowFields;
+ f.ShowInterfaces = options.ShowInterfaces;
+ f.ShowMethods = options.ShowMethods;
+ f.ShowProperties = options.ShowProperties;
+ f.ShowTypeProperties = options.ShowTypeProperties;
+ f.ShowInheritedMembers = options.ShowInheritedMembers;
+ f.ShowNonPublic = options.ShowNonPublic;
+ f.ShowMonoBroken = options.ShowMonoBroken;
+ f.FlattenHierarchy = options.FlattenHierarchy;
+ }
+
+ return finder;
+ }
+
+ public static INodeFormatter CreateFormatter (TypeReflectorOptions options)
+ {
+ return Factories.Formatter.Create (options.Formatter);
+ }
+ }
+}
+
namespace Mono.TypeReflector
{
- internal class TypeReflectorOptions : ProgramOptions {
+ public class TypeReflectorOptions : ProgramOptions {
private static char onlyAssemblies = 'A';
private static char addAssemblies = 'a';
private static string version = "version";
private static string formatter = "formatter";
private static string finder = "finder";
+ private static string displayer = "displayer";
private static string maxDepth = "max-depth";
public TypeReflectorOptions ()
AddOption (showAll, "show-all",
"Show everything except System.Type "+
"properties, inherited members, non-public "+
- "members, and \"broken\" Mono attributes.");
+ "members, and \"broken\" Mono attributes. " +
+ "Equivalent to -bcefimp.");
AddOption (flattenHierarchy, "flatten-hierarchy",
"Static members of base types should be " +
"displayed.");
StringBuilder formatterDescription = new StringBuilder ();
formatterDescription.Append ("Experimental. Specify the output style touse. Available values are:");
- foreach (object o in Factories.FormatterFactory.Keys)
+ foreach (object o in Factories.Formatter.Keys)
formatterDescription.Append (string.Format ("\n{0}", o));
AddArgumentOption (formatter, formatterDescription.ToString(), "<formatter>");
StringBuilder finderDescription = new StringBuilder ();
finderDescription.Append ("Experimental. Specify how nodes are found. Available values are:");
- foreach (object o in Factories.FinderFactory.Keys)
+ foreach (object o in Factories.Finder.Keys)
finderDescription.Append (string.Format ("\n{0}", o));
AddArgumentOption (finder, finderDescription.ToString(), "<finder>");
+ StringBuilder displayerDescription = new StringBuilder ();
+ displayerDescription.Append ("Experimental. Specify where output should be displayed. Available values are:");
+ foreach (object o in Factories.Displayer.Keys)
+ displayerDescription.Append (string.Format ("\n{0}", o));
+ AddArgumentOption (displayer, displayerDescription.ToString(), "<displayer>");
+
AddOption (verboseOutput, "verbose-output",
"Print the contents of all the public " +
"attributes of the reflection information " +
}
}
+ public string Displayer {
+ get {
+ string s = base.FoundOptionValue (displayer);
+ if (s == null)
+ return "console";
+ return s;
+ }
+ }
+
public override string OptionsHelp {
get {
StringBuilder sb = new StringBuilder ();
sb.Append (base.OptionsHelp);
sb.Append (
"\n" +
+ tg0.Group (
+ "<types> is interpreted as a regular expression. As regular expression " +
+ "meta-characters are seldom used in class names, specifying a type name " +
+ "looks for all types that have the specified type name as a substring. " +
+ "To get a listing of all available types, pass '.' as the type. (Since " +
+ "regular expressions are used, '.' will match any character, thus matching " +
+ "all possible types.)") +
+ "\n\n" +
tg0.Group (
"<assembly-list> is a `" + Path.PathSeparator + "'-delimited list. " +
"For example, `" +
String.Format ("foo{0}bar{0}baz",
Path.PathSeparator) + "' is a valid list.\n") +
- "\n" +
- tg0.Group (
- "<types> is interpreted as a regular expression. As regular expression " +
- "meta-characters are seldom used in class names, specifying a type name " +
- "looks for all types that have the specified type name as a substring.") +
- "\n\n"
+ "\n"
);
sb.Append (String.Format (
"Examples:\n" +
--- /dev/null
+//
+// VBNodeFormatter.cs: Formats nodes with VB.NET syntax
+//
+// Author: Jonathan Pryor (jonpryor@vt.edu)
+//
+// (C) 2002 Jonathan Pryor
+//
+
+using System;
+using System.Collections;
+using System.IO;
+using System.Diagnostics;
+using System.Reflection;
+using System.Text;
+using System.Text.RegularExpressions;
+
+namespace Mono.TypeReflector
+{
+ public class VBNodeFormatter : LanguageNodeFormatter {
+
+ public VBNodeFormatter ()
+ {
+ }
+
+ protected override string LineComment {get {return "'";}}
+
+ protected override string KeywordClass {get {return "Class";}}
+ protected override string KeywordEnum {get {return "Enum";}}
+ protected override string KeywordValueType {get {return "Struct";}}
+ protected override string KeywordInterface {get {return "Interface";}}
+ protected override string KeywordInherits {get {return "Inherits";}}
+ protected override string KeywordImplements {get {return "Implements";}}
+ protected override string KeywordMulticast {get {return "Event";}}
+ protected override string KeywordStatementTerminator {get {return "";}}
+ protected override string KeywordStatementSeparator {get {return ",";}}
+
+ protected override string QualifierPublic {get {return "Public";}}
+ protected override string QualifierFamily {get {return "Family";}}
+ protected override string QualifierAssembly {get {return "Internal";}}
+ protected override string QualifierPrivate {get {return "Private";}}
+ protected override string QualifierFinal {get {return "Final";}}
+ protected override string QualifierStatic {get {return "Shared";}}
+ protected override string QualifierLiteral {get {return "Const";}}
+ protected override string QualifierAbstract {get {return "Abstract";}}
+ protected override string QualifierVirtual {get {return "Overridable";}}
+
+ private static readonly string[] attributeDelimeters = new string[]{"<", ">"};
+
+ protected override string[] AttributeDelimeters {
+ get {return attributeDelimeters;}
+ }
+
+ protected override string GetConstructorName (ConstructorInfo ctor)
+ {
+ return "Sub New";
+ }
+
+ protected override void AddMethodDeclaration (StringBuilder sb, MethodInfo method)
+ {
+ string type = "Function";
+
+ bool sub = method.ReturnType == typeof(System.Void);
+
+ if (sub) {
+ type = "Sub";
+ }
+
+ sb.AppendFormat ("{0} {1}", type, method.Name);
+ AddMethodArgs (sb, method);
+
+ if (!sub)
+ sb.AppendFormat (" As {0}", method.ReturnType);
+ }
+ }
+}
+
--- /dev/null
+//
+// ConsoleTypeDisplayer.cs:
+// Display types on the console.
+//
+// Author: Jonathan Pryor (jonpryor@vt.edu)
+//
+// (C) 2002 Jonathan Pryor
+//
+
+// #define TRACE
+
+using System;
+using System.Collections;
+using System.IO;
+using System.Diagnostics;
+using System.Reflection;
+using System.Text;
+using System.Text.RegularExpressions;
+
+namespace Mono.TypeReflector
+{
+ public class ConsoleTypeDisplayer : TypeDisplayer
+ {
+ private IndentingTextWriter writer = new IndentingTextWriter (Console.Out);
+
+ // `ReflectionTypeDisplayer.PrintTypeProperties' is recursive, but refrains
+ // from printing duplicates. Despite duplicate removal, the output for
+ // printing the Properties of System.Type is > 800K of text.
+ //
+ // 3 levels permits viewing Attribute values, but not the attributes of
+ // those attribute values.
+ //
+ // For example, 3 levels permits:
+ // class System.Type {depth 0}
+ // Properties: {depth 1}
+ // System.Reflection.MemberTypes MemberType {depth 2}
+ // - CanRead=True {depth 3}
+ // - CanWrite=False {depth 3}
+ // ...
+ private int maxDepth = 3;
+
+ public override int MaxDepth {
+ set {maxDepth = value;}
+ }
+
+ public override bool RequireTypes {
+ get {return true;}
+ }
+
+ public ConsoleTypeDisplayer ()
+ {
+ }
+
+ public override void Run ()
+ {
+ foreach (Assembly a in Assemblies) {
+ writer.WriteLine ("Assembly: FullName='{0}'; Location='{1}'",
+ a.FullName, a.Location);
+ using (Indenter i = Indent()) {
+ foreach (string ns in Namespaces(a)) {
+ writer.WriteLine ("Namespace: {0}", ns);
+ using (Indenter i2 = Indent()) {
+ foreach (Type type in Types (a, ns)) {
+ Node root = new Node (Formatter, Finder);
+ // new GroupingNodeFinder (f));
+ // new ExplicitNodeFinder());
+ // root.Extra = new NodeInfo (null, type, NodeTypes.Type);
+ root.NodeInfo = new NodeInfo (null, type);
+ ShowNode (root, writer, maxDepth);
+ writer.WriteLine ();
+ }
+ }
+ }
+ }
+ }
+ }
+
+ private static void ShowNode (Node root, IndentingTextWriter writer, int maxDepth)
+ {
+ writer.WriteLine (root.Description);
+ if (maxDepth > 0) {
+ using (Indenter i = new Indenter (writer)) {
+ foreach (Node child in root.GetChildren()) {
+ ShowNode (child, writer, maxDepth-1);
+ }
+ }
+ }
+ }
+
+ private Indenter Indent ()
+ {
+ return new Indenter (writer);
+ }
+ }
+}
+
--- /dev/null
+//
+// ITypeDisplayer.cs:
+// Framework interface for the displaying of types to a display device (e.g.
+// console or GUI program).
+//
+// Author: Jonathan Pryor (jonpryor@vt.edu)
+//
+// (C) 2002 Jonathan Pryor
+//
+
+using System;
+
+namespace Mono.TypeReflector
+{
+ public interface ITypeDisplayer
+ {
+ INodeFormatter Formatter {set;}
+ INodeFinder Finder {set;}
+ TypeReflectorOptions Options {set;}
+ int MaxDepth {set;}
+ bool RequireTypes {get;}
+
+ void AddType (Type n);
+
+ void Run ();
+ }
+}
+
public override void Write (string value)
{
+ string[] lines = value.Split ('\n');
+ _Write (lines[0]);
+ if (lines.Length > 1) {
+ WriteLine ();
+ for (int i = 1; i != lines.Length; ++i)
+ _WriteLine (lines[i]);
+ }
+ }
+
+ private void _Write (string value)
+ {
if (NeedIndent)
WriteIndent ();
_writer.Write (value);
- }
+ }
public override void WriteLine ()
{
public override void WriteLine (string value)
{
+ string[] lines = value.Split ('\n');
+ foreach (string s in lines)
+ _WriteLine (s);
+ }
+
+ private void _WriteLine (string value)
+ {
Trace.WriteLineIf (info.Enabled, String.Format(
"WriteLine: NeedIndent={0}", NeedIndent));
if (NeedIndent)
WriteIndent ();
_writer.WriteLine (value);
NeedIndent = true;
- }
+ }
}
public class Indenter : IDisposable {
--- /dev/null
+//
+// TypeDisplayer.cs:
+// Common ITypeDisplayer operations
+//
+// Author: Jonathan Pryor (jonpryor@vt.edu)
+//
+// (C) 2002 Jonathan Pryor
+//
+
+// #define TRACE
+
+using System;
+using System.Collections;
+using System.IO;
+using System.Diagnostics;
+using System.Reflection;
+using System.Text;
+using System.Text.RegularExpressions;
+
+namespace Mono.TypeReflector
+{
+ sealed class DisplayerComparer : IComparer
+ {
+ public static readonly DisplayerComparer Default;
+
+ static DisplayerComparer ()
+ {
+ Default = new DisplayerComparer ();
+ }
+
+ // we store either Assembly's or strings; handle both.
+ public int Compare (object a, object b)
+ {
+ if (a is Assembly) {
+ Assembly aa = (Assembly) a;
+ Assembly ab = (Assembly) b;
+ return aa.FullName.CompareTo (ab.FullName);
+ }
+ if (a is Type) {
+ Type ta = (Type) a;
+ Type tb = (Type) b;
+ return ta.FullName.CompareTo (tb.FullName);
+ }
+ return Comparer.Default.Compare (a, b);
+ }
+ }
+
+ public abstract class TypeDisplayer : ITypeDisplayer
+ {
+ private INodeFormatter formatter;
+ private INodeFinder finder;
+ private TypeReflectorOptions options;
+
+ // type: map<Assembly, map<Namespace, list<Type> > >
+ private IDictionary types = CreateDictionary ();
+
+ public TypeDisplayer ()
+ {
+ }
+
+ public INodeFormatter Formatter {
+ get {return formatter;}
+ set {formatter = value;}
+ }
+
+ public INodeFinder Finder {
+ get {return finder;}
+ set {finder = value;}
+ }
+
+ public TypeReflectorOptions Options {
+ get {return options;}
+ set {options = value;}
+ }
+
+ public abstract int MaxDepth {set;}
+ public abstract bool RequireTypes {get;}
+
+ protected ICollection Assemblies {
+ get {return types.Keys;}
+ }
+
+ private static IDictionary CreateDictionary ()
+ {
+ return new SortedList (DisplayerComparer.Default);
+ }
+
+ protected ICollection Namespaces (Assembly a)
+ {
+ return _Namespaces(a).Keys;
+ }
+
+ protected ICollection Types (Assembly a, string ns)
+ {
+ // return (ICollection) _Namespaces(a)[ns];
+ return _Types (_Namespaces(a), ns).Keys;
+ }
+
+ private IDictionary _Namespaces (Assembly a)
+ {
+ IDictionary d = (IDictionary) types[a];
+ if (d == null) {
+ d = CreateDictionary ();
+ types[a] = d;
+ }
+ return d;
+ }
+
+ private IDictionary _Types (IDictionary namespaces, string ns)
+ {
+ IDictionary list = (IDictionary) namespaces[ns];
+ if (list == null) {
+ list = CreateDictionary ();
+ namespaces[ns] = list;
+ }
+ return list;
+ }
+
+ public virtual void AddType (Type type)
+ {
+ _Types(_Namespaces(type.Assembly), type.Namespace)[type] = null;
+ }
+
+ public abstract void Run ();
+ }
+}
+
--- /dev/null
+2002-12-31 Jonathan Pryor <jonpryor@vt.edu>
+ * ChangeLog: Added
+ * GtkTypeDisplayer.cs: Gtk# front-end for reflection information
+ * type-reflector.glade: Glade description for Gtk# front-end
+ * type-reflector.gladep: Glade Project file
+
--- /dev/null
+//
+// GtkTypeDisplayer.cs:
+// Display types using Gtk#.
+//
+// Author: Jonathan Pryor (jonpryor@vt.edu)
+//
+// (C) 2002 Jonathan Pryor
+//
+
+// #define TRACE
+
+using System;
+using System.Collections;
+using System.IO;
+using System.Diagnostics;
+using System.Reflection;
+using System.Text;
+using System.Text.RegularExpressions;
+
+// for GUI support
+using GLib;
+using Glade;
+using Gtk;
+using GtkSharp;
+using System.Drawing;
+
+namespace Mono.TypeReflector
+{
+ delegate void OpenFileSuccess (string filename);
+
+ class OpenFileDialog
+ {
+ private FileSelection file = new FileSelection ("Open an Assembly");
+ private OpenFileSuccess onSuccess;
+
+ public OpenFileDialog (OpenFileSuccess success)
+ {
+ onSuccess = success;
+ file.DeleteEvent += new DeleteEventHandler (delete_event);
+ file.CancelButton.Clicked += new EventHandler (cancel_event);
+ file.OkButton.Clicked += new EventHandler (ok_event);
+ file.Show ();
+ }
+
+ private void delete_event (object o, DeleteEventArgs args)
+ {
+ cancel_event (o, args);
+ }
+
+ private void cancel_event (object o, EventArgs args)
+ {
+ file.Hide ();
+ }
+
+ private void ok_event (object o, EventArgs args)
+ {
+ file.Hide ();
+ onSuccess (file.Filename);
+ }
+ }
+
+ public class GtkTypeDisplayer : TypeDisplayer
+ {
+ private TreeStore store;
+ private Window mainWindow;
+ private Statusbar statusbar;
+ private Window aboutWindow;
+ private static int windows = 0;
+
+ public override int MaxDepth {
+ set {/* ignore */}
+ }
+
+ public override bool RequireTypes {
+ get {return false;}
+ }
+
+ public GtkTypeDisplayer ()
+ {
+ Console.WriteLine ("GtkTypeDisplayer created");
+ if (++windows == 1)
+ Application.Init ();
+
+ InitMainWindow ();
+ }
+
+ private void InitMainWindow ()
+ {
+ Glade.XML gxml = new Glade.XML (null, "gtk/type-reflector.glade", "main_window", null);
+ try {
+ gxml.Autoconnect (this);
+ } catch (Exception e) {
+ Console.WriteLine ("** Error with glade: " + e.ToString());
+ throw;
+ }
+
+ store = new TreeStore ((int) TypeFundamentals.TypeString);
+
+ TreeView tv = (TreeView) gxml ["treeview"];
+ tv.Model = store;
+ // tv.HeadersVisible = true;
+ tv.HeadersVisible = false;
+ tv.RowExpanded += new RowExpandedHandler (RowExpanded);
+
+ TreeViewColumn nameCol = new TreeViewColumn ();
+ CellRenderer nameRenderer = new CellRendererText ();
+ nameCol.Title = "Stuff";
+ nameCol.PackStart (nameRenderer, true);
+ nameCol.AddAttribute (nameRenderer, "text", 0);
+ tv.AppendColumn (nameCol);
+
+ mainWindow = (Window) gxml ["main_window"];
+ statusbar = (Statusbar) gxml ["status_bar"];
+ }
+
+ private void RowExpanded (object o, RowExpandedArgs args)
+ {
+ Console.WriteLine ("** row expanded!");
+ Console.WriteLine (" ** Iter={0}, Path={1}", args.Iter, args.Path);
+ /*
+ NodeValue v = new NodeValue ();
+ store.GetValue (args.Iter, 0, v);
+ string s = (string) v;
+ Console.WriteLine (" ** v.Node={0}; v={1}", v.Node, s);
+ GLib.Value gv = new GLib.Value ();
+ store.GetValue (args.Iter, 1, gv);
+ GLib.Object go = (GLib.Object) gv;
+ NodeInfo ni = (NodeInfo) go.GetData ("mykey");
+ Console.WriteLine (" ** ni={0}", ni);
+ */
+ }
+
+ private Node CreateNode (Type type)
+ {
+ Node root = new Node (Formatter, Finder);
+ root.NodeInfo = new NodeInfo (null, type);
+ return root;
+ }
+
+ public override void AddType (Type type)
+ {
+ Console.WriteLine ("Adding Type: " + type.FullName);
+ base.AddType (type);
+ }
+
+ public override void Run ()
+ {
+ ShowTypes();
+ Application.Run ();
+ }
+
+ private void ShowTypes ()
+ {
+ Console.WriteLine ("Showing Types...");
+ foreach (Assembly a in Assemblies) {
+ Console.WriteLine ("Assembly: " + a.FullName);
+ TreeIter ai;
+ store.Append (out ai);
+ store.SetValue (ai, 0, new GLib.Value (string.Format ("Assembly: {0}", a.FullName)));
+
+ foreach (string ns in Namespaces (a)) {
+ Console.WriteLine ("Namespace: " + ns);
+ TreeIter ni;
+ store.Append (out ni, ai);
+ store.SetValue (ni, 0, new GLib.Value (string.Format ("Namespace: {0}", ns)));
+ foreach (Type type in Types (a, ns))
+ AddType (type, ni);
+ }
+ }
+ Console.WriteLine ("----");
+
+ mainWindow.ShowAll ();
+ }
+
+ private void AddType (Type type, TreeIter parent)
+ {
+ Console.WriteLine ("Type: " + type.FullName);
+ TreeIter p;
+ store.Append (out p, parent);
+ // store.SetValue (p, 0, new NodeValue (CreateNode(type)));
+ NodeInfo r = new NodeInfo (null, type);
+ store.SetValue (p, 0, new GLib.Value (Formatter.GetDescription (r)));
+
+ foreach (NodeInfo ni in Finder.GetChildren (r)) {
+ TreeIter i;
+ store.Append (out i, p);
+ store.SetValue (i, 0,
+ new GLib.Value (Formatter.GetDescription (ni)));
+ TreeIter j;
+ store.Append (out j, i);
+ store.SetValue (j, 0, new GLib.Value ("Dummy"));
+ }
+ }
+
+ // Gtk#/Glade# Required Functions...
+ public void on_main_window_delete_event (object o, DeleteEventArgs args)
+ {
+ on_file_quit_activate (o, args);
+ }
+
+ public void on_file_new_activate (object o, EventArgs args)
+ {
+ /* ignore */
+ }
+
+ public void on_file_open_activate (object o, EventArgs args)
+ {
+ OpenFileDialog ofd = new OpenFileDialog (new OpenFileSuccess (OpenAssembly));
+ }
+
+ private void OpenAssembly (string assembly)
+ {
+ GtkTypeDisplayer d = new GtkTypeDisplayer ();
+ d.Finder = Finder;
+ d.Formatter = Formatter;
+ d.Options = Options;
+ TypeLoader tl = TypeReflectorApp.CreateLoader (Options);
+ tl.Assemblies = new string[]{assembly};
+ try {
+ TypeReflectorApp.FindTypes (d, tl, new string[]{"."});
+ d.ShowTypes ();
+ }
+ catch (Exception e) {
+ // should be an Alert.
+ Console.WriteLine ("Unable to load Assembly '{0}': {1}",
+ assembly, e.ToString());
+ }
+ }
+
+ public void on_ok_button_clicked (object o, EventArgs args)
+ {
+ Console.WriteLine ("ok clicked; args=" + args);
+ }
+
+ public void on_file_save_activate (object o, EventArgs args)
+ {
+ /* ignore */
+ }
+
+ public void on_file_save_as_activate (object o, EventArgs args)
+ {
+ /* ignore */
+ }
+
+ public void on_file_quit_activate (object o, EventArgs args)
+ {
+ if (--windows == 0)
+ Application.Quit ();
+ }
+
+ public void on_edit_cut_activate (object o, EventArgs args)
+ {
+ /* ignore */
+ }
+
+ public void on_edit_copy_activate (object o, EventArgs args)
+ {
+ /* ignore */
+ }
+
+ public void on_edit_paste_activate (object o, EventArgs args)
+ {
+ /* ignore */
+ }
+
+ public void on_edit_delete_activate (object o, EventArgs args)
+ {
+ /* ignore */
+ }
+
+ public void on_view_formatter_default_activate (object o, EventArgs args)
+ {
+ }
+
+ public void on_view_formatter_vb_activate (object o, EventArgs args)
+ {
+ }
+
+ public void on_view_formatter_csharp_activate (object o, EventArgs args)
+ {
+ }
+
+ public void on_view_finder_reflection_activate (object o, EventArgs args)
+ {
+ }
+
+ public void on_view_finder_explicit_activate (object o, EventArgs args)
+ {
+ }
+
+ public void on_help_about_activate (object o, EventArgs args)
+ {
+ /* ignore */
+ TypeReflectorApp.PrintVersion ();
+ Glade.XML gxml = new Glade.XML (null, "gtk/type-reflector.glade", "about_window", null);
+ try {
+ gxml.Autoconnect (this);
+ } catch (Exception e) {
+ Console.WriteLine ("** Error with glade: " + e.ToString());
+ throw;
+ }
+
+ aboutWindow = (Window) gxml ["about_window"];
+ }
+ }
+}
+
--- /dev/null
+<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
+<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
+
+<glade-interface>
+<requires lib="gnome"/>
+
+<widget class="GtkWindow" id="main_window">
+ <property name="visible">True</property>
+ <property name="title" translatable="yes">Type Reflector</property>
+ <property name="type">GTK_WINDOW_TOPLEVEL</property>
+ <property name="window_position">GTK_WIN_POS_NONE</property>
+ <property name="modal">False</property>
+ <property name="default_width">640</property>
+ <property name="default_height">480</property>
+ <property name="resizable">True</property>
+ <property name="destroy_with_parent">False</property>
+ <accessibility>
+ <atkproperty name="AtkObject::accessible_name" translatable="yes">Type Reflector</atkproperty>
+ </accessibility>
+ <signal name="delete_event" handler="on_main_window_delete_event" last_modification_time="Fri, 27 Dec 2002 01:50:35 GMT"/>
+
+ <child>
+ <widget class="GtkVBox" id="vbox1">
+ <property name="visible">True</property>
+ <property name="homogeneous">False</property>
+ <property name="spacing">0</property>
+
+ <child>
+ <widget class="GtkMenuBar" id="menu_bar">
+ <property name="visible">True</property>
+ <accessibility>
+ <atkproperty name="AtkObject::accessible_name" translatable="yes">Menu</atkproperty>
+ </accessibility>
+
+ <child>
+ <widget class="GtkMenuItem" id="file_menu">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_File</property>
+ <property name="use_underline">True</property>
+
+ <child>
+ <widget class="GtkMenu" id="file_menu_menu">
+
+ <child>
+ <widget class="GtkImageMenuItem" id="file_new">
+ <property name="visible">True</property>
+ <property name="label">gtk-new</property>
+ <property name="use_stock">True</property>
+ <signal name="activate" handler="on_file_new_activate" last_modification_time="Fri, 27 Dec 2002 02:00:50 GMT"/>
+ <accelerator key="N" modifiers="GDK_CONTROL_MASK" signal="activate"/>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkImageMenuItem" id="file_open">
+ <property name="visible">True</property>
+ <property name="label">gtk-open</property>
+ <property name="use_stock">True</property>
+ <signal name="activate" handler="on_file_open_activate" last_modification_time="Fri, 27 Dec 2002 02:01:00 GMT"/>
+ <accelerator key="O" modifiers="GDK_CONTROL_MASK" signal="activate"/>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkImageMenuItem" id="file_save">
+ <property name="visible">True</property>
+ <property name="label">gtk-save</property>
+ <property name="use_stock">True</property>
+ <signal name="activate" handler="on_file_save_activate" last_modification_time="Fri, 27 Dec 2002 02:01:07 GMT"/>
+ <accelerator key="S" modifiers="GDK_CONTROL_MASK" signal="activate"/>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkImageMenuItem" id="file_save_as">
+ <property name="visible">True</property>
+ <property name="label">gtk-save-as</property>
+ <property name="use_stock">True</property>
+ <signal name="activate" handler="on_file_save_as_activate" last_modification_time="Fri, 27 Dec 2002 02:01:14 GMT"/>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkMenuItem" id="file_separatormenuitem1">
+ <property name="visible">True</property>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkImageMenuItem" id="file_quit">
+ <property name="visible">True</property>
+ <property name="label">gtk-quit</property>
+ <property name="use_stock">True</property>
+ <signal name="activate" handler="on_file_quit_activate" last_modification_time="Fri, 27 Dec 2002 01:56:45 GMT"/>
+ <accelerator key="Q" modifiers="GDK_CONTROL_MASK" signal="activate"/>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkMenuItem" id="edit_menu">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_Edit</property>
+ <property name="use_underline">True</property>
+
+ <child>
+ <widget class="GtkMenu" id="edit_menu_menu">
+
+ <child>
+ <widget class="GtkImageMenuItem" id="edit_cut">
+ <property name="visible">True</property>
+ <property name="label">gtk-cut</property>
+ <property name="use_stock">True</property>
+ <signal name="activate" handler="on_edit_cut_activate" last_modification_time="Fri, 27 Dec 2002 02:30:09 GMT"/>
+ <accelerator key="X" modifiers="GDK_CONTROL_MASK" signal="activate"/>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkImageMenuItem" id="edit_copy">
+ <property name="visible">True</property>
+ <property name="label">gtk-copy</property>
+ <property name="use_stock">True</property>
+ <signal name="activate" handler="on_edit_copy_activate" last_modification_time="Fri, 27 Dec 2002 02:30:35 GMT"/>
+ <accelerator key="C" modifiers="GDK_CONTROL_MASK" signal="activate"/>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkImageMenuItem" id="edit_paste">
+ <property name="visible">True</property>
+ <property name="label">gtk-paste</property>
+ <property name="use_stock">True</property>
+ <signal name="activate" handler="on_edit_paste_activate" last_modification_time="Fri, 27 Dec 2002 02:30:46 GMT"/>
+ <accelerator key="V" modifiers="GDK_CONTROL_MASK" signal="activate"/>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkImageMenuItem" id="edit_delete">
+ <property name="visible">True</property>
+ <property name="label">gtk-delete</property>
+ <property name="use_stock">True</property>
+ <signal name="activate" handler="on_edit_delete_activate" last_modification_time="Fri, 27 Dec 2002 02:31:06 GMT"/>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkMenuItem" id="view_menu">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_View</property>
+ <property name="use_underline">True</property>
+
+ <child>
+ <widget class="GtkMenu" id="view_menu_menu">
+
+ <child>
+ <widget class="GtkImageMenuItem" id="view_formatter">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">F_ormatter</property>
+ <property name="use_underline">True</property>
+
+ <child internal-child="image">
+ <widget class="GtkImage" id="image10">
+ <property name="visible">True</property>
+ <property name="stock">gtk-select-color</property>
+ <property name="icon_size">1</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkMenu" id="view_formatter_menu">
+
+ <child>
+ <widget class="GtkRadioMenuItem" id="view_formatter_default">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Default</property>
+ <property name="use_underline">True</property>
+ <property name="active">True</property>
+ <signal name="activate" handler="on_view_formatter_default_activate" last_modification_time="Fri, 27 Dec 2002 03:00:29 GMT"/>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkRadioMenuItem" id="view_formatter_vb">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Visual Basic .NET</property>
+ <property name="use_underline">True</property>
+ <property name="active">False</property>
+ <property name="group">view_formatter_default</property>
+ <signal name="activate" handler="on_view_formatter_vb_activate" last_modification_time="Fri, 27 Dec 2002 03:00:29 GMT"/>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkRadioMenuItem" id="view_formatter_csharp">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">C#</property>
+ <property name="use_underline">True</property>
+ <property name="active">False</property>
+ <property name="group">view_formatter_default</property>
+ <signal name="activate" handler="on_view_formatter_csharp_activate" last_modification_time="Fri, 27 Dec 2002 03:00:29 GMT"/>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkImageMenuItem" id="view_finder">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">F_inder</property>
+ <property name="use_underline">True</property>
+
+ <child internal-child="image">
+ <widget class="GtkImage" id="image11">
+ <property name="visible">True</property>
+ <property name="stock">gtk-convert</property>
+ <property name="icon_size">1</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkMenu" id="view_finder_menu">
+
+ <child>
+ <widget class="GtkRadioMenuItem" id="view_finder_explicit">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Explicit</property>
+ <property name="use_underline">True</property>
+ <property name="active">True</property>
+ <signal name="activate" handler="on_view_finder_explicit_activate" last_modification_time="Fri, 27 Dec 2002 03:00:29 GMT"/>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkRadioMenuItem" id="view_finder_reflection">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Reflection</property>
+ <property name="use_underline">True</property>
+ <property name="active">False</property>
+ <property name="group">view_finder_explicit</property>
+ <signal name="activate" handler="on_view_finder_reflection_activate" last_modification_time="Fri, 27 Dec 2002 03:00:29 GMT"/>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkMenuItem" id="help_menu">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_Help</property>
+ <property name="use_underline">True</property>
+
+ <child>
+ <widget class="GtkMenu" id="help_menu_menu">
+
+ <child>
+ <widget class="GtkImageMenuItem" id="help_about">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">About</property>
+ <property name="use_underline">True</property>
+ <signal name="activate" handler="on_help_about_activate" last_modification_time="Fri, 27 Dec 2002 01:56:33 GMT"/>
+
+ <child internal-child="image">
+ <widget class="GtkImage" id="image12">
+ <property name="visible">True</property>
+ <property name="stock">gnome-stock-about</property>
+ <property name="icon_size">1</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkHandleBox" id="handlebox1">
+ <property name="visible">True</property>
+ <property name="shadow_type">GTK_SHADOW_OUT</property>
+ <property name="handle_position">GTK_POS_LEFT</property>
+ <property name="snap_edge">GTK_POS_TOP</property>
+
+ <child>
+ <widget class="GtkToolbar" id="toolbar2">
+ <property name="visible">True</property>
+ <property name="orientation">GTK_ORIENTATION_HORIZONTAL</property>
+ <property name="toolbar_style">GTK_TOOLBAR_BOTH</property>
+ <property name="tooltips">True</property>
+
+ <child>
+ <widget class="GtkButton" id="open_button">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="relief">GTK_RELIEF_NORMAL</property>
+ <signal name="clicked" handler="on_file_open_activate" last_modification_time="Fri, 27 Dec 2002 18:57:38 GMT"/>
+
+ <child>
+ <widget class="GtkHBox" id="hbox1">
+ <property name="visible">True</property>
+ <property name="homogeneous">False</property>
+ <property name="spacing">0</property>
+
+ <child>
+ <widget class="GtkImage" id="image13">
+ <property name="visible">True</property>
+ <property name="stock">gtk-open</property>
+ <property name="icon_size">4</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkLabel" id="label1">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Open</property>
+ <property name="use_underline">False</property>
+ <property name="use_markup">False</property>
+ <property name="justify">GTK_JUSTIFY_LEFT</property>
+ <property name="wrap">False</property>
+ <property name="selectable">False</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkButton" id="preferences_button">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="relief">GTK_RELIEF_NORMAL</property>
+
+ <child>
+ <widget class="GtkHBox" id="hbox2">
+ <property name="visible">True</property>
+ <property name="homogeneous">False</property>
+ <property name="spacing">0</property>
+
+ <child>
+ <widget class="GtkImage" id="image14">
+ <property name="visible">True</property>
+ <property name="stock">gtk-preferences</property>
+ <property name="icon_size">4</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkLabel" id="label2">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Preferences</property>
+ <property name="use_underline">False</property>
+ <property name="use_markup">False</property>
+ <property name="justify">GTK_JUSTIFY_LEFT</property>
+ <property name="wrap">False</property>
+ <property name="selectable">False</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkScrolledWindow" id="scrolledwindow1">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="hscrollbar_policy">GTK_POLICY_ALWAYS</property>
+ <property name="vscrollbar_policy">GTK_POLICY_ALWAYS</property>
+ <property name="shadow_type">GTK_SHADOW_NONE</property>
+ <property name="window_placement">GTK_CORNER_TOP_LEFT</property>
+
+ <child>
+ <widget class="GtkTreeView" id="treeview">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="headers_visible">False</property>
+ <property name="rules_hint">True</property>
+ <property name="reorderable">False</property>
+ <property name="enable_search">True</property>
+ </widget>
+ </child>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkStatusbar" id="status_bar">
+ <property name="visible">True</property>
+ <property name="has_resize_grip">True</property>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+ </widget>
+ </child>
+</widget>
+
+<widget class="GnomeAbout" id="about_window">
+ <property name="visible">True</property>
+ <property name="destroy_with_parent">False</property>
+ <property name="copyright" translatable="yes">(C) 2002 Jonathan Pryor</property>
+ <property name="comments" translatable="yes">Displays System.Reflection information about .NET types.</property>
+ <property name="authors">Jonathan Pryor</property>
+ <property name="documenters">Jonathan Pryor</property>
+ <property name="translator_credits" translatable="yes">translator_credits</property>
+</widget>
+
+</glade-interface>
--- /dev/null
+<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
+<!DOCTYPE glade-project SYSTEM "http://glade.gnome.org/glade-project-2.0.dtd">
+
+<glade-project>
+ <name>Type Reflector</name>
+ <program_name>type-reflector</program_name>
+ <gnome_support>FALSE</gnome_support>
+</glade-project>
return count;
}
- protected override void GetTypeChildren (NodeInfoCollection c, NodeInfo parent, Type type)
+ protected override void AddTypeChildren (NodeInfoCollection c, NodeInfo parent, Type type)
{
object instance = parent.ReflectionInstance;
}
}
- protected override void GetFieldChildren (NodeInfoCollection c, NodeInfo parent, FieldInfo field)
+ protected override void AddFieldChildren (NodeInfoCollection c, NodeInfo parent, FieldInfo field)
{
Trace.WriteLineIf (info.Enabled, "Getting Field Children");
AddMemberChildren (parent, field, c);
}
}
- protected override void GetParameterChildren (NodeInfoCollection c, NodeInfo parent, ParameterInfo pi)
+ protected override void AddParameterChildren (NodeInfoCollection c, NodeInfo parent, ParameterInfo pi)
{
// TODO: handle custom attributes...
// c.Add (new NodeInfo (parent, pi, customAttributes, NodeTypes.Other));
AddMembers (parent, pi, "Position", c);
}
- protected override void GetConstructorChildren (NodeInfoCollection c, NodeInfo parent, ConstructorInfo node)
+ protected override void AddConstructorChildren (NodeInfoCollection c, NodeInfo parent, ConstructorInfo node)
{
AddMethodBaseChildren (parent, node, c);
}
- protected override void GetEventChildren (NodeInfoCollection c, NodeInfo parent, EventInfo node)
+ protected override void AddEventChildren (NodeInfoCollection c, NodeInfo parent, EventInfo node)
{
AddMemberChildren (parent, node, c);
AddMembers (parent, node, "Attributes", c);
AddMembers (parent, node, "IsSpecialName", c);
}
- protected override void GetMethodChildren (NodeInfoCollection c, NodeInfo parent, MethodInfo node)
+ protected override void AddMethodChildren (NodeInfoCollection c, NodeInfo parent, MethodInfo node)
{
AddMethodBaseChildren (parent, node, c);
AddMembers (parent, node, "ReturnType", c);
}
}
- protected override void GetPropertyChildren (NodeInfoCollection c, NodeInfo parent, PropertyInfo node)
+ protected override void AddPropertyChildren (NodeInfoCollection c, NodeInfo parent, PropertyInfo node)
{
AddMemberChildren (parent, node, c);
AddMembers (parent, node, "Attributes", c);
private bool verboseOutput = false;
private bool showMonoBroken = false;
- // `ReflectionTypeDisplayer.PrintTypeProperties' is recursive, but refrains
- // from printing duplicates. Despite duplicate removal, the output for
- // printing the Properties of System.Type is > 800K of text.
- //
- // 3 levels permits viewing Attribute values, but not the attributes of
- // those attribute values.
- //
- // For example, 3 levels permits:
- // class System.Type {depth 0}
- // Properties: {depth 1}
- // System.Reflection.MemberTypes MemberType {depth 2}
- // - CanRead=True {depth 3}
- // - CanWrite=False {depth 3}
- // ...
- private int maxDepth = 3;
-
- public int MaxDepth {
- get {return maxDepth;}
- set {maxDepth = value;}
- }
-
public bool ShowBase {
get {return showBase;}
set {showBase = value;}
// always handle NodeTypes.Type
if (root.NodeType == NodeTypes.Type)
- GetTypeChildren (c, root, (Type) root.ReflectionObject);
+ AddTypeChildren (c, root, (Type) root.ReflectionObject);
else if (VerboseOutput) {
switch (root.NodeType) {
case NodeTypes.BaseType:
- GetBaseTypeChildren (c, root, (Type) root.ReflectionObject);
+ AddBaseTypeChildren (c, root, (Type) root.ReflectionObject);
break;
case NodeTypes.Interface:
- GetInterfaceChildren (c, root, (Type) root.ReflectionObject);
+ AddInterfaceChildren (c, root, (Type) root.ReflectionObject);
break;
case NodeTypes.Field:
- GetFieldChildren (c, root, (FieldInfo) root.ReflectionObject);
+ AddFieldChildren (c, root, (FieldInfo) root.ReflectionObject);
break;
case NodeTypes.Constructor:
- GetConstructorChildren (c, root, (ConstructorInfo) root.ReflectionObject);
+ AddConstructorChildren (c, root, (ConstructorInfo) root.ReflectionObject);
break;
case NodeTypes.Method:
- GetMethodChildren (c, root, (MethodInfo) root.ReflectionObject);
+ AddMethodChildren (c, root, (MethodInfo) root.ReflectionObject);
break;
case NodeTypes.Parameter:
- GetParameterChildren (c, root, (ParameterInfo) root.ReflectionObject);
+ AddParameterChildren (c, root, (ParameterInfo) root.ReflectionObject);
break;
case NodeTypes.Property:
- GetPropertyChildren (c, root, (PropertyInfo) root.ReflectionObject);
+ AddPropertyChildren (c, root, (PropertyInfo) root.ReflectionObject);
break;
case NodeTypes.Event:
- GetEventChildren (c, root, (EventInfo) root.ReflectionObject);
+ AddEventChildren (c, root, (EventInfo) root.ReflectionObject);
break;
case NodeTypes.ReturnValue:
- GetReturnValueChildren (c, root);
+ AddReturnValueChildren (c, root);
break;
case NodeTypes.Other:
case NodeTypes.Alias:
- GetOtherChildren (c, root);
+ AddOtherChildren (c, root);
break;
default:
- GetUnhandledChildren (c, root);
+ AddUnhandledChildren (c, root);
break;
}
}
return c;
}
- protected virtual void GetTypeChildren (NodeInfoCollection c, NodeInfo root, Type type)
+ protected virtual void AddTypeChildren (NodeInfoCollection c, NodeInfo root, Type type)
{
}
- protected virtual void GetBaseTypeChildren (NodeInfoCollection c, NodeInfo root, Type baseType)
+ protected virtual void AddBaseTypeChildren (NodeInfoCollection c, NodeInfo root, Type baseType)
{
}
- protected virtual void GetInterfaceChildren (NodeInfoCollection c, NodeInfo root, Type iface)
+ protected virtual void AddInterfaceChildren (NodeInfoCollection c, NodeInfo root, Type iface)
{
}
- protected virtual void GetFieldChildren (NodeInfoCollection c, NodeInfo root, FieldInfo field)
+ protected virtual void AddFieldChildren (NodeInfoCollection c, NodeInfo root, FieldInfo field)
{
- Console.WriteLine ("** field children b");
}
- protected virtual void GetConstructorChildren (NodeInfoCollection c, NodeInfo root, ConstructorInfo ctor)
+ protected virtual void AddConstructorChildren (NodeInfoCollection c, NodeInfo root, ConstructorInfo ctor)
{
}
- protected virtual void GetMethodChildren (NodeInfoCollection c, NodeInfo root, MethodInfo method)
+ protected virtual void AddMethodChildren (NodeInfoCollection c, NodeInfo root, MethodInfo method)
{
}
- protected virtual void GetParameterChildren (NodeInfoCollection c, NodeInfo root, ParameterInfo param)
+ protected virtual void AddParameterChildren (NodeInfoCollection c, NodeInfo root, ParameterInfo param)
{
}
- protected virtual void GetPropertyChildren (NodeInfoCollection c, NodeInfo root, PropertyInfo property)
+ protected virtual void AddPropertyChildren (NodeInfoCollection c, NodeInfo root, PropertyInfo property)
{
}
- protected virtual void GetEventChildren (NodeInfoCollection c, NodeInfo root, EventInfo e)
+ protected virtual void AddEventChildren (NodeInfoCollection c, NodeInfo root, EventInfo e)
{
}
- protected virtual void GetReturnValueChildren (NodeInfoCollection c, NodeInfo root)
+ protected virtual void AddReturnValueChildren (NodeInfoCollection c, NodeInfo root)
{
if (root.ReflectionObject != null)
- GetTypeChildren (c, root, (Type) root.ReflectionObject);
+ AddTypeChildren (c, root, (Type) root.ReflectionObject);
}
- protected virtual void GetOtherChildren (NodeInfoCollection c, NodeInfo root)
+ protected virtual void AddOtherChildren (NodeInfoCollection c, NodeInfo root)
{
if (root.Description is NodeGroup) {
NodeGroup g = (NodeGroup) root.Description;
}
}
- protected virtual void GetUnhandledChildren (NodeInfoCollection c, NodeInfo root)
+ protected virtual void AddUnhandledChildren (NodeInfoCollection c, NodeInfo root)
{
c.Add (new NodeInfo (root, "Unhandled child: NodeType=" + root.NodeType));
}
private static readonly IComparer NameComparer = new MemberInfoNameComparer ();
- protected override void GetTypeChildren (NodeInfoCollection c, NodeInfo parent, Type type)
+ protected override void AddTypeChildren (NodeInfoCollection c, NodeInfo parent, Type type)
{
foreach (MemberInfo mi in GetMembers (type)) {
AddNode (c, parent, mi, mi);
}
}
- protected override void GetFieldChildren (NodeInfoCollection c, NodeInfo parent, FieldInfo field)
+ protected override void AddFieldChildren (NodeInfoCollection c, NodeInfo parent, FieldInfo field)
{
AddSubnodes (c, parent, field.GetType(), field);
}
- protected override void GetConstructorChildren (NodeInfoCollection c, NodeInfo parent, ConstructorInfo ctor)
+ protected override void AddConstructorChildren (NodeInfoCollection c, NodeInfo parent, ConstructorInfo ctor)
{
GetMethodBaseChildren (c, parent, ctor);
}
- protected override void GetMethodChildren (NodeInfoCollection c, NodeInfo parent, MethodInfo method)
+ protected override void AddMethodChildren (NodeInfoCollection c, NodeInfo parent, MethodInfo method)
{
GetMethodBaseChildren (c, parent, method);
}
AddSubnodes (c, parent, mb.GetType(), mb);
}
- protected override void GetParameterChildren (NodeInfoCollection c, NodeInfo parent, ParameterInfo param)
+ protected override void AddParameterChildren (NodeInfoCollection c, NodeInfo parent, ParameterInfo param)
{
AddSubnodes (c, parent, param.GetType(), param);
}
- protected override void GetPropertyChildren (NodeInfoCollection c, NodeInfo parent, PropertyInfo pi)
+ protected override void AddPropertyChildren (NodeInfoCollection c, NodeInfo parent, PropertyInfo pi)
{
AddSubnodes (c, parent, pi.GetType(), pi);
}
- protected override void GetEventChildren (NodeInfoCollection c, NodeInfo parent, EventInfo e)
+ protected override void AddEventChildren (NodeInfoCollection c, NodeInfo parent, EventInfo e)
{
AddSubnodes (c, parent, e.GetType(), e);
}
- protected override void GetReturnValueChildren (NodeInfoCollection c, NodeInfo parent)
+ protected override void AddReturnValueChildren (NodeInfoCollection c, NodeInfo parent)
{
if (parent.ReflectionObject != null)
- GetTypeChildren (c, parent, (Type) parent.ReflectionObject);
+ AddTypeChildren (c, parent, (Type) parent.ReflectionObject);
}
}
}
{
}
- protected override string GetTypeDescription (Type type, object instance)
- {
- StringBuilder sb = new StringBuilder ();
- GetAttributes (sb, type);
- sb.Append (base.GetTypeDescription (type, instance));
- return sb.ToString();
- }
-
- private void GetAttributes (StringBuilder sb, MemberInfo m)
- {
- GetAttributes (sb, m, true);
- }
-
- private void GetAttributes (StringBuilder sb, MemberInfo m, bool newline)
- {
- GetCilAttributes (sb, m, newline);
- sb.Append (GetCustomAttributes (m, "", newline));
- }
-
- private void GetCilAttributes (StringBuilder sb, MemberInfo m, bool newline)
- {
- Type t = m as Type;
- MethodBase mb = m as MethodBase;
- if (t != null)
- GetCilAttributes (sb, t, newline);
- else if (mb != null)
- GetCilAttributes (sb, mb, newline);
- }
-
- private void GetCilAttributes (StringBuilder sb, Type t, bool newline)
- {
- if (t.IsSerializable) {
- sb.Append ("[Serializable]");
- if (newline)
- sb.Append ("\n");
- }
- }
-
- private void GetCilAttributes (StringBuilder sb, MethodBase m, bool newline)
- {
- MethodImplAttributes attr = m.GetMethodImplementationFlags ();
- if ((attr & MethodImplAttributes.InternalCall) != 0) {
- sb.Append ("[MethodImplAttribute(MethodImplOptions.InternalCall)]");
- if (newline)
- sb.Append ("\n");
- }
- }
-
- protected override string GetBaseTypeDescription (Type type, object instance)
- {
- return ": " + type.Name;
- }
-
- protected override string GetInterfaceDescription (Type type, object instance)
- {
- return ", " + type.Name;
- }
-
- protected override string GetConstructorDescription (ConstructorInfo ctor, object instance)
- {
- StringBuilder sb = new StringBuilder ();
- GetAttributes (sb, ctor);
- GetMethodQualifiers (sb, ctor);
- sb.AppendFormat ("{0} ", ctor.DeclaringType.Name);
- GetMethodArgs (sb, ctor);
-
- return sb.ToString();
- }
-
- private void GetMethodQualifiers (StringBuilder sb, MethodBase m)
- {
- if (m.IsPublic)
- sb.Append ("public ");
- if (m.IsFamily)
- sb.Append ("protected ");
- if (m.IsAssembly)
- sb.Append ("internal ");
- if (m.IsPrivate)
- sb.Append ("private ");
- if (m.IsStatic)
- sb.Append ("static ");
- if (m.IsFinal)
- sb.Append ("sealed ");
- if (m.IsAbstract)
- sb.Append ("abstract ");
- else if (m.IsVirtual)
- sb.Append ("virtual ");
- }
-
- private void GetMethodArgs (StringBuilder sb, MethodBase m)
- {
- sb.Append ("(");
- ParameterInfo[] parms = m.GetParameters ();
- if (parms.Length != 0) {
- int cur = 0;
- foreach (ParameterInfo pi in parms) {
- sb.Append (GetParameterDescription (pi, pi));
- if (cur++ != (parms.Length-1))
- sb.Append (", ");
- }
- }
- sb.Append (")");
- }
+ protected override string LineComment {get {return "//";}}
- protected override string GetEventDescription (EventInfo e, object instance)
- {
- StringBuilder sb = new StringBuilder ();
- GetMethodQualifiers (sb, e.GetAddMethod (true));
- return String.Format ("{0}{1}{2} {3}",
- sb.ToString(),
- e.IsMulticast ? "event " : "",
- e.EventHandlerType,
- e.Name);
- }
-
- protected override string GetFieldDescription (FieldInfo field, object instance)
- {
- StringBuilder sb = new StringBuilder ();
+ protected override string KeywordClass {get {return "class";}}
+ protected override string KeywordEnum {get {return "enum";}}
+ protected override string KeywordValueType {get {return "struct";}}
+ protected override string KeywordInterface {get {return "interface";}}
+ protected override string KeywordInherits {get {return ":";}}
+ protected override string KeywordImplements {get {return ",";}}
+ protected override string KeywordMulticast {get {return "event";}}
+ protected override string KeywordStatementTerminator {get {return ";";}}
+ protected override string KeywordStatementSeparator {get {return ",";}}
- GetAttributes (sb, field);
-
- if (!field.DeclaringType.IsEnum || field.IsSpecialName) {
- if (field.IsPublic)
- sb.Append ("public ");
- if (field.IsPrivate)
- sb.Append ("private ");
- if (field.IsAssembly)
- sb.Append ("internal ");
- if (field.IsFamily)
- sb.Append ("protected ");
- if (field.IsLiteral)
- sb.Append ("const ");
- else if (field.IsStatic)
- sb.Append ("static ");
-
- sb.AppendFormat ("{0} ", field.FieldType);
- }
-
- sb.AppendFormat ("{0}", field.Name);
-
- try {
- sb.AppendFormat (" = {0}", GetValue (field.GetValue (instance)));
- }
- catch {
- }
-
- if (!field.DeclaringType.IsEnum || field.IsSpecialName)
- sb.Append (";");
- else
- sb.Append (",");
-
- return sb.ToString ();
- }
-
- protected override string GetMethodDescription (MethodInfo method, object instance)
- {
- StringBuilder sb = new StringBuilder ();
-
- if (method.IsSpecialName)
- sb.Append ("/* Method is a specially named method:\n");
-
- GetAttributes (sb, method);
- if (method.ReturnTypeCustomAttributes != null) {
- sb.Append (GetCustomAttributes (method.ReturnTypeCustomAttributes, "return: ", true));
- }
- GetMethodQualifiers (sb, method);
- sb.AppendFormat ("{0} {1} ", method.ReturnType, method.Name);
- GetMethodArgs (sb, method);
-
- if (method.GetParameters().Length == 0) {
- try {
- object r = method.Invoke (instance, null);
- string s = GetValue (r);
- sb.AppendFormat ("={0}", s);
- }
- catch {
- }
- }
-
- if (method.IsSpecialName) {
- sb.Append ("\n */");
- }
-
- return sb.ToString();
- }
-
- protected override string GetParameterDescription (ParameterInfo param, object instance)
- {
- StringBuilder sb = new StringBuilder ();
-
- sb.Append (GetCustomAttributes (param, "", false));
- if (param.IsOut)
- sb.Append ("out ");
- sb.AppendFormat ("{0} {1}", param.ParameterType, param.Name);
-
- return sb.ToString();
- }
-
- protected override string GetPropertyDescription (PropertyInfo property, object instance)
- {
- StringBuilder sb = new StringBuilder ();
- GetAttributes (sb, property);
- GetMethodQualifiers (sb, property.GetAccessors(true)[0]);
+ protected override string QualifierPublic {get {return "public";}}
+ protected override string QualifierFamily {get {return "protected";}}
+ protected override string QualifierAssembly {get {return "internal";}}
+ protected override string QualifierPrivate {get {return "private";}}
+ protected override string QualifierFinal {get {return "sealed";}}
+ protected override string QualifierStatic {get {return "static";}}
+ protected override string QualifierLiteral {get {return "const";}}
+ protected override string QualifierAbstract {get {return "abstract";}}
+ protected override string QualifierVirtual {get {return "virtual";}}
- sb.AppendFormat ("{0} {1} {{", property.PropertyType, property.Name);
- if (property.CanRead) {
- sb.Append ("get");
- try {
- sb.AppendFormat (" /* = {0} */", GetValue (property.GetValue (instance, null)));
- }
- catch {
- }
- sb.Append ("; ");
- }
- if (property.CanWrite)
- sb.Append ("set; ");
- sb.Append ("}}");
+ private static readonly string[] attributeDelimeters = new string[]{"[", "]"};
- return sb.ToString();
+ protected override string[] AttributeDelimeters {
+ get {return attributeDelimeters;}
}
- protected override string GetReturnValueDescription (NodeInfo n)
+ protected override string GetConstructorName (ConstructorInfo ctor)
{
- return string.Format ("/* ReturnValue={0} */", GetOtherDescription (n));
+ return ctor.DeclaringType.Name;
}
}
}
namespace Mono.TypeReflector
{
- public class LanguageNodeFormatter : NodeFormatter {
+ public abstract class LanguageNodeFormatter : NodeFormatter {
+
+ protected abstract string LineComment {get;}
+
+ // [0] is open, [1] is close
+ protected abstract string[] AttributeDelimeters {get;}
+
+ protected abstract string KeywordClass {get;}
+ protected abstract string KeywordEnum {get;}
+ protected abstract string KeywordValueType {get;}
+ protected abstract string KeywordInterface {get;}
+ protected abstract string KeywordInherits {get;}
+ protected abstract string KeywordImplements {get;}
+ protected abstract string KeywordMulticast {get;}
+ protected abstract string KeywordStatementTerminator {get;}
+ protected abstract string KeywordStatementSeparator {get;}
+
+ protected abstract string QualifierPublic {get;}
+ protected abstract string QualifierFamily {get;}
+ protected abstract string QualifierAssembly {get;}
+ protected abstract string QualifierPrivate {get;}
+ protected abstract string QualifierStatic {get;}
+ protected abstract string QualifierFinal {get;}
+ protected abstract string QualifierAbstract {get;}
+ protected abstract string QualifierVirtual {get;}
+ protected abstract string QualifierLiteral {get;}
protected override string GetTypeDescription (Type type, object instance)
{
- return string.Format ("{0} {1}", GetTypeKeyword(type), type.Name);
+ StringBuilder sb = new StringBuilder ();
+ AddAttributes (sb, type);
+ AddTypeQualifiers (sb, type);
+ sb.AppendFormat ("{0} {1}", GetTypeKeyword(type), type.FullName);
+ return sb.ToString ();
+ }
+
+ protected void AddAttribute (StringBuilder sb, string attribute)
+ {
+ sb.AppendFormat ("{0}{1}{2}",
+ AttributeDelimeters[0], attribute, AttributeDelimeters[1]);
+ }
+
+ protected void AddAttributes (StringBuilder sb, MemberInfo m)
+ {
+ AddAttributes (sb, m, true);
+ }
+
+ protected void AddAttributes (StringBuilder sb, MemberInfo m, bool newline)
+ {
+ AddCilAttributes (sb, m, newline);
+ AddCustomAttributes (sb, m, "", newline);
+ }
+
+ private void AddCilAttributes (StringBuilder sb, MemberInfo m, bool newline)
+ {
+ Type t = m as Type;
+ MethodBase mb = m as MethodBase;
+ if (t != null)
+ AddCilAttributes (sb, t, newline);
+ else if (mb != null)
+ AddCilAttributes (sb, mb, newline);
+ }
+
+ private void AddCilAttributes (StringBuilder sb, Type t, bool newline)
+ {
+ if (t.IsSerializable) {
+ AddAttribute (sb, "Serializable");
+ if (newline)
+ sb.Append ("\n");
+ }
+ }
+
+ private void AddCilAttributes (StringBuilder sb, MethodBase m, bool newline)
+ {
+ MethodImplAttributes attr = m.GetMethodImplementationFlags ();
+ if ((attr & MethodImplAttributes.InternalCall) != 0) {
+ AddAttribute (sb, "MethodImplAttribute(MethodImplOptions.InternalCall)");
+ if (newline)
+ sb.Append ("\n");
+ }
+ }
+
+ protected void AddTypeQualifiers (StringBuilder sb, Type type)
+ {
+ if (type.IsPublic)
+ sb.Append (QualifierPublic + " ");
+ if (type.IsSealed && !type.IsValueType)
+ sb.Append (QualifierFinal + " ");
+ if (type.IsAbstract && !type.IsInterface)
+ sb.Append (QualifierAbstract + " ");
+ }
+
+ new protected string GetTypeKeyword (Type type)
+ {
+ if (type.IsClass)
+ return KeywordClass;
+ if (type.IsEnum)
+ return KeywordEnum;
+ if (type.IsValueType)
+ return KeywordValueType;
+ if (type.IsInterface)
+ return KeywordInterface;
+
+ // unknown type
+ return "type";
}
protected override string GetBaseTypeDescription (Type type, object instance)
{
- return type.Name;
+ if (type != null)
+ return string.Format ("{0} {1}", KeywordInherits, type.Name);
+ return string.Format ("{0} No Base Type", LineComment);
}
protected override string GetInterfaceDescription (Type type, object instance)
{
- return type.Name;
+ return string.Format ("{0} {1}", KeywordImplements, type.Name);
}
protected override string GetConstructorDescription (ConstructorInfo ctor, object instance)
{
- return string.Format ("{0} ({1})", ctor.Name, ctor.GetParameters().Length);
- // return ctor.Name;
+ StringBuilder sb = new StringBuilder ();
+ AddAttributes (sb, ctor);
+ AddMethodQualifiers (sb, ctor);
+ sb.AppendFormat ("{0} ", GetConstructorName (ctor));
+ AddMethodArgs (sb, ctor);
+
+ return sb.ToString();
+ }
+
+ protected void AddMethodQualifiers (StringBuilder sb, MethodBase m)
+ {
+ if (m.IsPublic)
+ sb.AppendFormat ("{0} ", QualifierPublic);
+ if (m.IsFamily)
+ sb.AppendFormat ("{0} ", QualifierFamily);
+ if (m.IsAssembly)
+ sb.AppendFormat ("{0} ", QualifierAssembly);
+ if (m.IsPrivate)
+ sb.AppendFormat ("{0} ", QualifierPrivate);
+ if (m.IsStatic)
+ sb.AppendFormat ("{0} ", QualifierStatic);
+ if (m.IsFinal)
+ sb.AppendFormat ("{0} ", QualifierFinal);
+ if (m.IsAbstract)
+ sb.AppendFormat ("{0} ", QualifierAbstract);
+ else if (m.IsVirtual)
+ sb.AppendFormat ("{0} ", QualifierVirtual);
+ }
+
+ protected abstract string GetConstructorName (ConstructorInfo ctor);
+
+ protected void AddMethodArgs (StringBuilder sb, MethodBase m)
+ {
+ sb.Append ("(");
+ ParameterInfo[] parms = m.GetParameters ();
+ if (parms.Length != 0) {
+ int cur = 0;
+ foreach (ParameterInfo pi in parms) {
+ sb.Append (GetParameterDescription (pi, pi));
+ if (cur++ != (parms.Length-1))
+ sb.Append (", ");
+ }
+ }
+ sb.Append (")");
}
protected override string GetEventDescription (EventInfo e, object instance)
{
- return e.Name;
+ StringBuilder sb = new StringBuilder ();
+ AddMethodQualifiers (sb, e.GetAddMethod(true));
+ return string.Format ("{0}{1}{2} {3}",
+ sb.ToString (),
+ e.IsMulticast ? KeywordMulticast + " " : "",
+ e.EventHandlerType,
+ e.Name);
}
protected override string GetFieldDescription (FieldInfo field, object instance)
{
+ StringBuilder sb = new StringBuilder ();
+ AddAttributes (sb, field);
+
+ if (!field.DeclaringType.IsEnum || field.IsSpecialName) {
+ AddFieldQualifiers (sb, field);
+ sb.AppendFormat ("{0} ", field.FieldType);
+ }
+
+ sb.Append (field.Name);
+
try {
- return string.Format ("{0}={1}", field.Name,
- // GetValue (field, instance));
- GetValue (instance));
- } catch {
- return field.Name;
+ sb.AppendFormat (" = {0}", GetValue (field.GetValue (instance)));
+ }
+ catch {
}
+
+ if (!field.DeclaringType.IsEnum || field.IsSpecialName)
+ sb.Append (KeywordStatementTerminator);
+ else
+ sb.Append (KeywordStatementSeparator);
+
+ return sb.ToString();
}
- protected override string GetMethodDescription (MethodInfo mb, object instance)
+ protected void AddFieldQualifiers (StringBuilder sb, FieldInfo field)
{
- if (mb.GetParameters().Length == 0) {
+ if (field.IsPublic)
+ sb.AppendFormat ("{0} ", QualifierPublic);
+ if (field.IsPrivate)
+ sb.AppendFormat ("{0} ", QualifierPrivate);
+ if (field.IsAssembly)
+ sb.AppendFormat ("{0} ", QualifierAssembly);
+ if (field.IsFamily)
+ sb.AppendFormat ("{0} ", QualifierFamily);
+ if (field.IsLiteral)
+ sb.AppendFormat ("{0} ", QualifierLiteral);
+ else if (field.IsStatic)
+ sb.AppendFormat ("{0} ", QualifierStatic);
+ }
+
+ protected override string GetMethodDescription (MethodInfo method, object instance)
+ {
+ StringBuilder sb = new StringBuilder ();
+
+ if (method.IsSpecialName)
+ sb.AppendFormat ("{0} Method is a specially named method:\n", LineComment);
+
+ AddAttributes (sb, method);
+ if (method.ReturnTypeCustomAttributes != null)
+ AddCustomAttributes (sb, method.ReturnTypeCustomAttributes, "return: ", true);
+
+ AddMethodQualifiers (sb, method);
+
+ AddMethodDeclaration (sb, method);
+
+ if (method.GetParameters().Length == 0) {
try {
- object r = mb.Invoke (instance, null);
+ object r = method.Invoke (instance, null);
string s = GetValue (r);
- return string.Format ("{0}()={1}", mb.Name, s);
+ sb.AppendFormat (" {0} = {1}", LineComment, s);
}
catch {
}
}
- return string.Format ("{0} ({1})", mb.Name, mb.GetParameters().Length);
+
+ string r = sb.ToString();
+
+ if (method.IsSpecialName)
+ return r.Replace ("\n", "\n" + LineComment + "\t");
+ return r;
+ }
+
+ protected virtual void AddMethodDeclaration (StringBuilder sb, MethodInfo method)
+ {
+ sb.AppendFormat ("{0} {1} ", method.ReturnType, method.Name);
+
+ AddMethodArgs (sb, method);
}
protected override string GetParameterDescription (ParameterInfo param, object instance)
{
- return param.Name;
+ StringBuilder sb = new StringBuilder ();
+
+ AddCustomAttributes (sb, param, "", false);
+ AddParameterAttributes (sb, param.Attributes);
+
+ sb.AppendFormat ("{0} {1}", param.ParameterType, param.Name);
+
+ return sb.ToString();
}
- protected override string GetPropertyDescription (PropertyInfo property, object instance)
+ protected void AddParameterAttributes (StringBuilder sb, ParameterAttributes attrs)
{
- string v = "";
- try {
- // object o = property.GetGetMethod(true).Invoke(instance, null);
- object o = property.GetValue (instance, null);
- v = string.Format ("={0}", GetValue (o));
- } catch {
- v = "";
- }
- return string.Format ("{0}{1}", property.Name, v);
- // return property.Name;
- // return string.Format ("{0}={1}", property.Name, property.GetValue(null));
+ if ((attrs & ParameterAttributes.In) != 0)
+ sb.Append ("in");
+ if ((attrs & ParameterAttributes.Out) != 0)
+ sb.Append ("out");
+ if ((attrs & ParameterAttributes.Lcid) != 0)
+ sb.Append ("lcid");
+ if ((attrs & ParameterAttributes.Retval) != 0)
+ sb.Append ("retval");
+ if ((attrs & ParameterAttributes.Optional) != 0)
+ sb.Append ("optional");
+ if ((attrs & ParameterAttributes.HasDefault) != 0)
+ sb.Append ("hasdefault");
+ if ((attrs & ParameterAttributes.HasFieldMarshal) != 0)
+ sb.Append ("hasfieldmarshal");
+ if ((attrs & ParameterAttributes.ReservedMask) != 0)
+ sb.Append ("reservedmask");
+ if ((attrs & ParameterAttributes.Reserved3) != 0)
+ sb.Append ("reserved3");
+ if ((attrs & ParameterAttributes.Reserved4) != 0)
+ sb.Append ("reserved4");
}
- protected override string GetCustomAttributeProviderDescription (ICustomAttributeProvider m, object instance)
+ protected override string GetPropertyDescription (PropertyInfo property, object instance)
{
StringBuilder sb = new StringBuilder ();
- foreach (object a in m.GetCustomAttributes(true)) {
- sb.Append (string.Format ("\n\t{0}", GetCustomAttribute(a)));
+ AddAttributes (sb, property);
+ AddMethodQualifiers (sb, property.GetAccessors(true)[0]);
+
+ sb.AppendFormat ("{0} {1} {{", property.PropertyType, property.Name);
+ if (property.CanRead) {
+ sb.Append ("get");
+ try {
+ sb.AppendFormat (" /* = {0} */", GetValue (property.GetValue (instance, null)));
+ }
+ catch {
+ }
+ sb.Append (";");
}
- return string.Format ("GetCustomAttributes()={0}{1}",
- sb.Length == 0 ? "<none/>" : "",
- sb.ToString());
+ if (property.CanWrite)
+ sb.Append ("set;");
+ sb.Append ("}}");
+
+ return sb.ToString();
}
- protected override string GetCustomAttributes (ICustomAttributeProvider m, string attributeType, bool newLine)
+ protected override string GetReturnValueDescription (NodeInfo n)
{
- StringBuilder sb = new StringBuilder ();
+ return string.Format ("{0} ReturnValue={1}",
+ LineComment, GetOtherDescription (n));
+ }
+
+ protected override string GetOtherDescription (NodeInfo node)
+ {
+ if (node.Description != null)
+ return node.Description.ToString();
+ return "<null other description/>";
+ }
+ protected void AddCustomAttributes (StringBuilder sb, ICustomAttributeProvider m, string attributeType, bool newLine)
+ {
object[] attrs = m.GetCustomAttributes (true);
foreach (object a in attrs) {
- GetCustomAttribute (sb, a, attributeType);
+ AddCustomAttribute (sb, a, attributeType);
if (newLine)
sb.Append ("\n");
}
-
- return sb.ToString ();
}
- protected override string GetCustomAttribute (object attribute)
- {
- StringBuilder sb = new StringBuilder ();
- GetCustomAttribute (sb, attribute, "");
- return sb.ToString();
- }
-
- protected override void GetCustomAttribute (StringBuilder sb, object attribute, string attributeType)
+ protected virtual void AddCustomAttribute (StringBuilder sb, object attribute, string attributeType)
{
Type type = attribute.GetType();
- char[] delims = GetAttributeDelimeters ();
- sb.AppendFormat ("{0}{1}{2}", delims[0], attributeType, type.FullName);
+ sb.AppendFormat ("{0}{1}{2}", AttributeDelimeters[0], attributeType, type.FullName);
- string p = GetPropertyValues (type.GetProperties(), attribute);
- string f = GetFieldValues (type.GetFields(), attribute);
+ PropertyInfo[] props = type.GetProperties();
+ FieldInfo[] fields = type.GetFields();
- if ((p.Length > 0) || (f.Length > 0)) {
+ if (props.Length > 0 || fields.Length > 0) {
sb.Append ("(");
- if (p.Length > 0) {
- sb.Append (p);
- if (f.Length > 0)
+ if (props.Length > 0) {
+ AddPropertyValues (sb, props, attribute);
+ if (fields.Length > 0)
sb.Append (", ");
}
- if (f.Length > 0)
- sb.Append (f);
+ if (fields.Length > 0)
+ AddFieldValues (sb, fields, attribute);
sb.Append (")");
}
-
- sb.Append (delims[1]);
+ sb.Append (AttributeDelimeters[1]);
}
- protected override char[] GetAttributeDelimeters ()
- {
- return new char[]{'[', ']'};
- }
-
- private string GetPropertyValues (PropertyInfo[] props, object instance)
+ private void AddPropertyValues (StringBuilder sb, PropertyInfo[] props, object instance)
{
int len = props.Length;
- StringBuilder sb = new StringBuilder ();
for (int i = 0; i != len; ++i) {
sb.Append (props[i].Name);
sb.Append ("=");
if (i != (len-1))
sb.Append (", ");
}
- return sb.ToString();
}
- private string GetFieldValues (FieldInfo[] fields, object instance)
+ private void AddFieldValues (StringBuilder sb, FieldInfo[] fields, object instance)
{
int len = fields.Length;
- StringBuilder sb = new StringBuilder ();
for (int i = 0; i != len; ++i) {
sb.Append (fields[i].Name);
sb.Append ("=");
if (i != (len-1))
sb.Append (", ");
}
- return sb.ToString();
}
- protected override string GetEncodedValue (object value)
+ protected virtual string GetEncodedValue (object value)
{
if (value == null)
return "null";
return value.ToString();
}
- protected override string GetEncodedCharValue (object value)
+ protected virtual string GetEncodedCharValue (object value)
{
return String.Format ("'{0}'", value.ToString());
}
- protected override string GetEncodedDecimalValue (object value)
+ protected virtual string GetEncodedDecimalValue (object value)
{
return String.Format ("{0}m", value.ToString());
}
- protected override string GetEncodedDoubleValue (object value)
+ protected virtual string GetEncodedDoubleValue (object value)
{
return String.Format ("{0}d", value.ToString());
}
- protected override string GetEncodedInt64Value (object value)
+ protected virtual string GetEncodedInt64Value (object value)
{
return String.Format ("{0}L", value.ToString());
}
- protected override string GetEncodedSingleValue (object value)
+ protected virtual string GetEncodedSingleValue (object value)
{
return String.Format ("{0}f", value.ToString());
}
- protected override string GetEncodedStringValue (object value)
+ protected virtual string GetEncodedStringValue (object value)
{
return String.Format ("\"{0}\"", value.ToString());
}
- protected override string GetEncodedUInt32Value (object value)
+ protected virtual string GetEncodedUInt32Value (object value)
{
return String.Format ("{0}U", value.ToString());
}
- protected override string GetEncodedUInt64Value (object value)
+ protected virtual string GetEncodedUInt64Value (object value)
{
return String.Format ("{0}UL", value.ToString());
}
- protected override string GetEncodedObjectValue (object value)
+ protected virtual string GetEncodedObjectValue (object value)
{
return String.Format ("typeof({0})", value.ToString());
}
-
- protected override string GetOtherDescription (NodeInfo node)
- {
- if (node.Description != null)
- return node.Description.ToString();
- return "<null other description/>";
- }
}
}
case NodeTypes.Event:
r = GetEventDescription ((EventInfo) node.ReflectionObject, node.ReflectionInstance);
break;
+ /*
case NodeTypes.CustomAttributeProvider:
r = GetCustomAttributeProviderDescription ((ICustomAttributeProvider) node.ReflectionObject, node.ReflectionInstance);
break;
+ */
case NodeTypes.Other:
case NodeTypes.Alias:
r = GetOtherDescription (node);
protected virtual string GetTypeDescription (Type type, object instance)
{
- return string.Format ("{0} {1}", GetTypeKeyword(type), type.FullName);
+ return string.Format ("{0} {1}",
+ GetTypeKeyword(type), type.FullName);
}
protected virtual string GetBaseTypeDescription (Type type, object instance)
{
- return type.Name;
+ if (type != null)
+ return type.Name;
+ return "No Base Type";
}
protected virtual string GetInterfaceDescription (Type type, object instance)
return property.Name;
}
- protected virtual string GetCustomAttributeProviderDescription (ICustomAttributeProvider m, object instance)
- {
- StringBuilder sb = new StringBuilder ();
- foreach (object a in m.GetCustomAttributes(true)) {
- sb.Append (string.Format ("\n\t{0}", GetCustomAttribute(a)));
- }
- return string.Format ("GetCustomAttributes()={0}{1}",
- sb.Length == 0 ? "<none/>" : "",
- sb.ToString());
- }
-
- protected virtual string GetCustomAttributes (ICustomAttributeProvider m, string attributeType, bool newLine)
- {
- StringBuilder sb = new StringBuilder ();
-
- object[] attrs = m.GetCustomAttributes (true);
-
- foreach (object a in attrs) {
-
- GetCustomAttribute (sb, a, attributeType);
-
- if (newLine)
- sb.Append ("\n");
- }
-
- return sb.ToString ();
- }
-
- protected virtual string GetCustomAttribute (object attribute)
- {
- StringBuilder sb = new StringBuilder ();
- GetCustomAttribute (sb, attribute, "");
- return sb.ToString();
- }
-
- protected virtual void GetCustomAttribute (StringBuilder sb, object attribute, string attributeType)
- {
- Type type = attribute.GetType();
- char[] delims = GetAttributeDelimeters ();
- sb.AppendFormat ("{0}{1}{2}", delims[0], attributeType, type.FullName);
-
- string p = GetPropertyValues (type.GetProperties(), attribute);
- string f = GetFieldValues (type.GetFields(), attribute);
-
- if ((p.Length > 0) || (f.Length > 0)) {
- sb.Append ("(");
- if (p.Length > 0) {
- sb.Append (p);
- if (f.Length > 0)
- sb.Append (", ");
- }
- if (f.Length > 0)
- sb.Append (f);
- sb.Append (")");
- }
-
- sb.Append (delims[1]);
- }
-
- protected virtual char[] GetAttributeDelimeters ()
- {
- return new char[]{'[', ']'};
- }
-
- private string GetPropertyValues (PropertyInfo[] props, object instance)
- {
- int len = props.Length;
- StringBuilder sb = new StringBuilder ();
- for (int i = 0; i != len; ++i) {
- sb.Append (props[i].Name);
- sb.Append ("=");
- try {
- sb.Append (GetEncodedValue (props[i].GetValue (instance, null)));
- } catch {
- sb.Append ("<exception/>");
- }
- if (i != (len-1))
- sb.Append (", ");
- }
- return sb.ToString();
- }
-
- private string GetFieldValues (FieldInfo[] fields, object instance)
- {
- int len = fields.Length;
- StringBuilder sb = new StringBuilder ();
- for (int i = 0; i != len; ++i) {
- sb.Append (fields[i].Name);
- sb.Append ("=");
- sb.Append (GetEncodedValue (fields[i].GetValue (instance)));
- if (i != (len-1))
- sb.Append (", ");
- }
- return sb.ToString();
- }
-
- protected virtual string GetEncodedValue (object value)
- {
- if (value == null)
- return "null";
-
- switch (Type.GetTypeCode(value.GetType())) {
- case TypeCode.Char:
- return GetEncodedCharValue (value);
- case TypeCode.Decimal:
- return GetEncodedDecimalValue (value);
- case TypeCode.Double:
- return GetEncodedDoubleValue (value);
- case TypeCode.Int64:
- return GetEncodedInt64Value (value);
- case TypeCode.Single:
- return GetEncodedSingleValue (value);
- case TypeCode.String:
- return GetEncodedStringValue (value);
- case TypeCode.UInt32:
- return GetEncodedUInt32Value (value);
- case TypeCode.UInt64:
- return GetEncodedUInt64Value (value);
- case TypeCode.Object:
- return GetEncodedObjectValue (value);
- }
- // not special-cased; just return it's value
- return value.ToString();
- }
-
- protected virtual string GetEncodedCharValue (object value)
- {
- return String.Format ("'{0}'", value.ToString());
- }
-
- protected virtual string GetEncodedDecimalValue (object value)
- {
- return String.Format ("{0}m", value.ToString());
- }
-
- protected virtual string GetEncodedDoubleValue (object value)
- {
- return String.Format ("{0}d", value.ToString());
- }
-
- protected virtual string GetEncodedInt64Value (object value)
- {
- return String.Format ("{0}L", value.ToString());
- }
-
- protected virtual string GetEncodedSingleValue (object value)
- {
- return String.Format ("{0}f", value.ToString());
- }
-
- protected virtual string GetEncodedStringValue (object value)
- {
- return String.Format ("\"{0}\"", value.ToString());
- }
-
- protected virtual string GetEncodedUInt32Value (object value)
- {
- return String.Format ("{0}U", value.ToString());
- }
-
- protected virtual string GetEncodedUInt64Value (object value)
- {
- return String.Format ("{0}UL", value.ToString());
- }
-
- protected virtual string GetEncodedObjectValue (object value)
- {
- return String.Format ("typeof({0})", value.ToString());
- }
-
protected virtual string GetOtherDescription (NodeInfo node)
{
if (node.Description != null)
--- /dev/null
+//
+// VBNodeFormatter.cs: Formats nodes with VB.NET syntax
+//
+// Author: Jonathan Pryor (jonpryor@vt.edu)
+//
+// (C) 2002 Jonathan Pryor
+//
+
+using System;
+using System.Collections;
+using System.IO;
+using System.Diagnostics;
+using System.Reflection;
+using System.Text;
+using System.Text.RegularExpressions;
+
+namespace Mono.TypeReflector
+{
+ public class VBNodeFormatter : LanguageNodeFormatter {
+
+ public VBNodeFormatter ()
+ {
+ }
+
+ protected override string LineComment {get {return "'";}}
+
+ protected override string KeywordClass {get {return "Class";}}
+ protected override string KeywordEnum {get {return "Enum";}}
+ protected override string KeywordValueType {get {return "Struct";}}
+ protected override string KeywordInterface {get {return "Interface";}}
+ protected override string KeywordInherits {get {return "Inherits";}}
+ protected override string KeywordImplements {get {return "Implements";}}
+ protected override string KeywordMulticast {get {return "Event";}}
+ protected override string KeywordStatementTerminator {get {return "";}}
+ protected override string KeywordStatementSeparator {get {return ",";}}
+
+ protected override string QualifierPublic {get {return "Public";}}
+ protected override string QualifierFamily {get {return "Family";}}
+ protected override string QualifierAssembly {get {return "Internal";}}
+ protected override string QualifierPrivate {get {return "Private";}}
+ protected override string QualifierFinal {get {return "Final";}}
+ protected override string QualifierStatic {get {return "Shared";}}
+ protected override string QualifierLiteral {get {return "Const";}}
+ protected override string QualifierAbstract {get {return "Abstract";}}
+ protected override string QualifierVirtual {get {return "Overridable";}}
+
+ private static readonly string[] attributeDelimeters = new string[]{"<", ">"};
+
+ protected override string[] AttributeDelimeters {
+ get {return attributeDelimeters;}
+ }
+
+ protected override string GetConstructorName (ConstructorInfo ctor)
+ {
+ return "Sub New";
+ }
+
+ protected override void AddMethodDeclaration (StringBuilder sb, MethodInfo method)
+ {
+ string type = "Function";
+
+ bool sub = method.ReturnType == typeof(System.Void);
+
+ if (sub) {
+ type = "Sub";
+ }
+
+ sb.AppendFormat ("{0} {1}", type, method.Name);
+ AddMethodArgs (sb, method);
+
+ if (!sub)
+ sb.AppendFormat (" As {0}", method.ReturnType);
+ }
+ }
+}
+
--- /dev/null
+2002-12-31 Jonathan Pryor <jonpryor@vt.edu>
+ * ChangeLog: Added
+ * GtkTypeDisplayer.cs: Gtk# front-end for reflection information
+ * type-reflector.glade: Glade description for Gtk# front-end
+ * type-reflector.gladep: Glade Project file
+
--- /dev/null
+//
+// GtkTypeDisplayer.cs:
+// Display types using Gtk#.
+//
+// Author: Jonathan Pryor (jonpryor@vt.edu)
+//
+// (C) 2002 Jonathan Pryor
+//
+
+// #define TRACE
+
+using System;
+using System.Collections;
+using System.IO;
+using System.Diagnostics;
+using System.Reflection;
+using System.Text;
+using System.Text.RegularExpressions;
+
+// for GUI support
+using GLib;
+using Glade;
+using Gtk;
+using GtkSharp;
+using System.Drawing;
+
+namespace Mono.TypeReflector
+{
+ delegate void OpenFileSuccess (string filename);
+
+ class OpenFileDialog
+ {
+ private FileSelection file = new FileSelection ("Open an Assembly");
+ private OpenFileSuccess onSuccess;
+
+ public OpenFileDialog (OpenFileSuccess success)
+ {
+ onSuccess = success;
+ file.DeleteEvent += new DeleteEventHandler (delete_event);
+ file.CancelButton.Clicked += new EventHandler (cancel_event);
+ file.OkButton.Clicked += new EventHandler (ok_event);
+ file.Show ();
+ }
+
+ private void delete_event (object o, DeleteEventArgs args)
+ {
+ cancel_event (o, args);
+ }
+
+ private void cancel_event (object o, EventArgs args)
+ {
+ file.Hide ();
+ }
+
+ private void ok_event (object o, EventArgs args)
+ {
+ file.Hide ();
+ onSuccess (file.Filename);
+ }
+ }
+
+ public class GtkTypeDisplayer : TypeDisplayer
+ {
+ private TreeStore store;
+ private Window mainWindow;
+ private Statusbar statusbar;
+ private Window aboutWindow;
+ private static int windows = 0;
+
+ public override int MaxDepth {
+ set {/* ignore */}
+ }
+
+ public override bool RequireTypes {
+ get {return false;}
+ }
+
+ public GtkTypeDisplayer ()
+ {
+ Console.WriteLine ("GtkTypeDisplayer created");
+ if (++windows == 1)
+ Application.Init ();
+
+ InitMainWindow ();
+ }
+
+ private void InitMainWindow ()
+ {
+ Glade.XML gxml = new Glade.XML (null, "gtk/type-reflector.glade", "main_window", null);
+ try {
+ gxml.Autoconnect (this);
+ } catch (Exception e) {
+ Console.WriteLine ("** Error with glade: " + e.ToString());
+ throw;
+ }
+
+ store = new TreeStore ((int) TypeFundamentals.TypeString);
+
+ TreeView tv = (TreeView) gxml ["treeview"];
+ tv.Model = store;
+ // tv.HeadersVisible = true;
+ tv.HeadersVisible = false;
+ tv.RowExpanded += new RowExpandedHandler (RowExpanded);
+
+ TreeViewColumn nameCol = new TreeViewColumn ();
+ CellRenderer nameRenderer = new CellRendererText ();
+ nameCol.Title = "Stuff";
+ nameCol.PackStart (nameRenderer, true);
+ nameCol.AddAttribute (nameRenderer, "text", 0);
+ tv.AppendColumn (nameCol);
+
+ mainWindow = (Window) gxml ["main_window"];
+ statusbar = (Statusbar) gxml ["status_bar"];
+ }
+
+ private void RowExpanded (object o, RowExpandedArgs args)
+ {
+ Console.WriteLine ("** row expanded!");
+ Console.WriteLine (" ** Iter={0}, Path={1}", args.Iter, args.Path);
+ /*
+ NodeValue v = new NodeValue ();
+ store.GetValue (args.Iter, 0, v);
+ string s = (string) v;
+ Console.WriteLine (" ** v.Node={0}; v={1}", v.Node, s);
+ GLib.Value gv = new GLib.Value ();
+ store.GetValue (args.Iter, 1, gv);
+ GLib.Object go = (GLib.Object) gv;
+ NodeInfo ni = (NodeInfo) go.GetData ("mykey");
+ Console.WriteLine (" ** ni={0}", ni);
+ */
+ }
+
+ private Node CreateNode (Type type)
+ {
+ Node root = new Node (Formatter, Finder);
+ root.NodeInfo = new NodeInfo (null, type);
+ return root;
+ }
+
+ public override void AddType (Type type)
+ {
+ Console.WriteLine ("Adding Type: " + type.FullName);
+ base.AddType (type);
+ }
+
+ public override void Run ()
+ {
+ ShowTypes();
+ Application.Run ();
+ }
+
+ private void ShowTypes ()
+ {
+ Console.WriteLine ("Showing Types...");
+ foreach (Assembly a in Assemblies) {
+ Console.WriteLine ("Assembly: " + a.FullName);
+ TreeIter ai;
+ store.Append (out ai);
+ store.SetValue (ai, 0, new GLib.Value (string.Format ("Assembly: {0}", a.FullName)));
+
+ foreach (string ns in Namespaces (a)) {
+ Console.WriteLine ("Namespace: " + ns);
+ TreeIter ni;
+ store.Append (out ni, ai);
+ store.SetValue (ni, 0, new GLib.Value (string.Format ("Namespace: {0}", ns)));
+ foreach (Type type in Types (a, ns))
+ AddType (type, ni);
+ }
+ }
+ Console.WriteLine ("----");
+
+ mainWindow.ShowAll ();
+ }
+
+ private void AddType (Type type, TreeIter parent)
+ {
+ Console.WriteLine ("Type: " + type.FullName);
+ TreeIter p;
+ store.Append (out p, parent);
+ // store.SetValue (p, 0, new NodeValue (CreateNode(type)));
+ NodeInfo r = new NodeInfo (null, type);
+ store.SetValue (p, 0, new GLib.Value (Formatter.GetDescription (r)));
+
+ foreach (NodeInfo ni in Finder.GetChildren (r)) {
+ TreeIter i;
+ store.Append (out i, p);
+ store.SetValue (i, 0,
+ new GLib.Value (Formatter.GetDescription (ni)));
+ TreeIter j;
+ store.Append (out j, i);
+ store.SetValue (j, 0, new GLib.Value ("Dummy"));
+ }
+ }
+
+ // Gtk#/Glade# Required Functions...
+ public void on_main_window_delete_event (object o, DeleteEventArgs args)
+ {
+ on_file_quit_activate (o, args);
+ }
+
+ public void on_file_new_activate (object o, EventArgs args)
+ {
+ /* ignore */
+ }
+
+ public void on_file_open_activate (object o, EventArgs args)
+ {
+ OpenFileDialog ofd = new OpenFileDialog (new OpenFileSuccess (OpenAssembly));
+ }
+
+ private void OpenAssembly (string assembly)
+ {
+ GtkTypeDisplayer d = new GtkTypeDisplayer ();
+ d.Finder = Finder;
+ d.Formatter = Formatter;
+ d.Options = Options;
+ TypeLoader tl = TypeReflectorApp.CreateLoader (Options);
+ tl.Assemblies = new string[]{assembly};
+ try {
+ TypeReflectorApp.FindTypes (d, tl, new string[]{"."});
+ d.ShowTypes ();
+ }
+ catch (Exception e) {
+ // should be an Alert.
+ Console.WriteLine ("Unable to load Assembly '{0}': {1}",
+ assembly, e.ToString());
+ }
+ }
+
+ public void on_ok_button_clicked (object o, EventArgs args)
+ {
+ Console.WriteLine ("ok clicked; args=" + args);
+ }
+
+ public void on_file_save_activate (object o, EventArgs args)
+ {
+ /* ignore */
+ }
+
+ public void on_file_save_as_activate (object o, EventArgs args)
+ {
+ /* ignore */
+ }
+
+ public void on_file_quit_activate (object o, EventArgs args)
+ {
+ if (--windows == 0)
+ Application.Quit ();
+ }
+
+ public void on_edit_cut_activate (object o, EventArgs args)
+ {
+ /* ignore */
+ }
+
+ public void on_edit_copy_activate (object o, EventArgs args)
+ {
+ /* ignore */
+ }
+
+ public void on_edit_paste_activate (object o, EventArgs args)
+ {
+ /* ignore */
+ }
+
+ public void on_edit_delete_activate (object o, EventArgs args)
+ {
+ /* ignore */
+ }
+
+ public void on_view_formatter_default_activate (object o, EventArgs args)
+ {
+ }
+
+ public void on_view_formatter_vb_activate (object o, EventArgs args)
+ {
+ }
+
+ public void on_view_formatter_csharp_activate (object o, EventArgs args)
+ {
+ }
+
+ public void on_view_finder_reflection_activate (object o, EventArgs args)
+ {
+ }
+
+ public void on_view_finder_explicit_activate (object o, EventArgs args)
+ {
+ }
+
+ public void on_help_about_activate (object o, EventArgs args)
+ {
+ /* ignore */
+ TypeReflectorApp.PrintVersion ();
+ Glade.XML gxml = new Glade.XML (null, "gtk/type-reflector.glade", "about_window", null);
+ try {
+ gxml.Autoconnect (this);
+ } catch (Exception e) {
+ Console.WriteLine ("** Error with glade: " + e.ToString());
+ throw;
+ }
+
+ aboutWindow = (Window) gxml ["about_window"];
+ }
+ }
+}
+
--- /dev/null
+<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
+<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
+
+<glade-interface>
+<requires lib="gnome"/>
+
+<widget class="GtkWindow" id="main_window">
+ <property name="visible">True</property>
+ <property name="title" translatable="yes">Type Reflector</property>
+ <property name="type">GTK_WINDOW_TOPLEVEL</property>
+ <property name="window_position">GTK_WIN_POS_NONE</property>
+ <property name="modal">False</property>
+ <property name="default_width">640</property>
+ <property name="default_height">480</property>
+ <property name="resizable">True</property>
+ <property name="destroy_with_parent">False</property>
+ <accessibility>
+ <atkproperty name="AtkObject::accessible_name" translatable="yes">Type Reflector</atkproperty>
+ </accessibility>
+ <signal name="delete_event" handler="on_main_window_delete_event" last_modification_time="Fri, 27 Dec 2002 01:50:35 GMT"/>
+
+ <child>
+ <widget class="GtkVBox" id="vbox1">
+ <property name="visible">True</property>
+ <property name="homogeneous">False</property>
+ <property name="spacing">0</property>
+
+ <child>
+ <widget class="GtkMenuBar" id="menu_bar">
+ <property name="visible">True</property>
+ <accessibility>
+ <atkproperty name="AtkObject::accessible_name" translatable="yes">Menu</atkproperty>
+ </accessibility>
+
+ <child>
+ <widget class="GtkMenuItem" id="file_menu">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_File</property>
+ <property name="use_underline">True</property>
+
+ <child>
+ <widget class="GtkMenu" id="file_menu_menu">
+
+ <child>
+ <widget class="GtkImageMenuItem" id="file_new">
+ <property name="visible">True</property>
+ <property name="label">gtk-new</property>
+ <property name="use_stock">True</property>
+ <signal name="activate" handler="on_file_new_activate" last_modification_time="Fri, 27 Dec 2002 02:00:50 GMT"/>
+ <accelerator key="N" modifiers="GDK_CONTROL_MASK" signal="activate"/>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkImageMenuItem" id="file_open">
+ <property name="visible">True</property>
+ <property name="label">gtk-open</property>
+ <property name="use_stock">True</property>
+ <signal name="activate" handler="on_file_open_activate" last_modification_time="Fri, 27 Dec 2002 02:01:00 GMT"/>
+ <accelerator key="O" modifiers="GDK_CONTROL_MASK" signal="activate"/>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkImageMenuItem" id="file_save">
+ <property name="visible">True</property>
+ <property name="label">gtk-save</property>
+ <property name="use_stock">True</property>
+ <signal name="activate" handler="on_file_save_activate" last_modification_time="Fri, 27 Dec 2002 02:01:07 GMT"/>
+ <accelerator key="S" modifiers="GDK_CONTROL_MASK" signal="activate"/>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkImageMenuItem" id="file_save_as">
+ <property name="visible">True</property>
+ <property name="label">gtk-save-as</property>
+ <property name="use_stock">True</property>
+ <signal name="activate" handler="on_file_save_as_activate" last_modification_time="Fri, 27 Dec 2002 02:01:14 GMT"/>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkMenuItem" id="file_separatormenuitem1">
+ <property name="visible">True</property>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkImageMenuItem" id="file_quit">
+ <property name="visible">True</property>
+ <property name="label">gtk-quit</property>
+ <property name="use_stock">True</property>
+ <signal name="activate" handler="on_file_quit_activate" last_modification_time="Fri, 27 Dec 2002 01:56:45 GMT"/>
+ <accelerator key="Q" modifiers="GDK_CONTROL_MASK" signal="activate"/>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkMenuItem" id="edit_menu">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_Edit</property>
+ <property name="use_underline">True</property>
+
+ <child>
+ <widget class="GtkMenu" id="edit_menu_menu">
+
+ <child>
+ <widget class="GtkImageMenuItem" id="edit_cut">
+ <property name="visible">True</property>
+ <property name="label">gtk-cut</property>
+ <property name="use_stock">True</property>
+ <signal name="activate" handler="on_edit_cut_activate" last_modification_time="Fri, 27 Dec 2002 02:30:09 GMT"/>
+ <accelerator key="X" modifiers="GDK_CONTROL_MASK" signal="activate"/>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkImageMenuItem" id="edit_copy">
+ <property name="visible">True</property>
+ <property name="label">gtk-copy</property>
+ <property name="use_stock">True</property>
+ <signal name="activate" handler="on_edit_copy_activate" last_modification_time="Fri, 27 Dec 2002 02:30:35 GMT"/>
+ <accelerator key="C" modifiers="GDK_CONTROL_MASK" signal="activate"/>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkImageMenuItem" id="edit_paste">
+ <property name="visible">True</property>
+ <property name="label">gtk-paste</property>
+ <property name="use_stock">True</property>
+ <signal name="activate" handler="on_edit_paste_activate" last_modification_time="Fri, 27 Dec 2002 02:30:46 GMT"/>
+ <accelerator key="V" modifiers="GDK_CONTROL_MASK" signal="activate"/>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkImageMenuItem" id="edit_delete">
+ <property name="visible">True</property>
+ <property name="label">gtk-delete</property>
+ <property name="use_stock">True</property>
+ <signal name="activate" handler="on_edit_delete_activate" last_modification_time="Fri, 27 Dec 2002 02:31:06 GMT"/>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkMenuItem" id="view_menu">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_View</property>
+ <property name="use_underline">True</property>
+
+ <child>
+ <widget class="GtkMenu" id="view_menu_menu">
+
+ <child>
+ <widget class="GtkImageMenuItem" id="view_formatter">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">F_ormatter</property>
+ <property name="use_underline">True</property>
+
+ <child internal-child="image">
+ <widget class="GtkImage" id="image10">
+ <property name="visible">True</property>
+ <property name="stock">gtk-select-color</property>
+ <property name="icon_size">1</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkMenu" id="view_formatter_menu">
+
+ <child>
+ <widget class="GtkRadioMenuItem" id="view_formatter_default">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Default</property>
+ <property name="use_underline">True</property>
+ <property name="active">True</property>
+ <signal name="activate" handler="on_view_formatter_default_activate" last_modification_time="Fri, 27 Dec 2002 03:00:29 GMT"/>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkRadioMenuItem" id="view_formatter_vb">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Visual Basic .NET</property>
+ <property name="use_underline">True</property>
+ <property name="active">False</property>
+ <property name="group">view_formatter_default</property>
+ <signal name="activate" handler="on_view_formatter_vb_activate" last_modification_time="Fri, 27 Dec 2002 03:00:29 GMT"/>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkRadioMenuItem" id="view_formatter_csharp">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">C#</property>
+ <property name="use_underline">True</property>
+ <property name="active">False</property>
+ <property name="group">view_formatter_default</property>
+ <signal name="activate" handler="on_view_formatter_csharp_activate" last_modification_time="Fri, 27 Dec 2002 03:00:29 GMT"/>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkImageMenuItem" id="view_finder">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">F_inder</property>
+ <property name="use_underline">True</property>
+
+ <child internal-child="image">
+ <widget class="GtkImage" id="image11">
+ <property name="visible">True</property>
+ <property name="stock">gtk-convert</property>
+ <property name="icon_size">1</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkMenu" id="view_finder_menu">
+
+ <child>
+ <widget class="GtkRadioMenuItem" id="view_finder_explicit">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Explicit</property>
+ <property name="use_underline">True</property>
+ <property name="active">True</property>
+ <signal name="activate" handler="on_view_finder_explicit_activate" last_modification_time="Fri, 27 Dec 2002 03:00:29 GMT"/>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkRadioMenuItem" id="view_finder_reflection">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Reflection</property>
+ <property name="use_underline">True</property>
+ <property name="active">False</property>
+ <property name="group">view_finder_explicit</property>
+ <signal name="activate" handler="on_view_finder_reflection_activate" last_modification_time="Fri, 27 Dec 2002 03:00:29 GMT"/>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkMenuItem" id="help_menu">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">_Help</property>
+ <property name="use_underline">True</property>
+
+ <child>
+ <widget class="GtkMenu" id="help_menu_menu">
+
+ <child>
+ <widget class="GtkImageMenuItem" id="help_about">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">About</property>
+ <property name="use_underline">True</property>
+ <signal name="activate" handler="on_help_about_activate" last_modification_time="Fri, 27 Dec 2002 01:56:33 GMT"/>
+
+ <child internal-child="image">
+ <widget class="GtkImage" id="image12">
+ <property name="visible">True</property>
+ <property name="stock">gnome-stock-about</property>
+ <property name="icon_size">1</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkHandleBox" id="handlebox1">
+ <property name="visible">True</property>
+ <property name="shadow_type">GTK_SHADOW_OUT</property>
+ <property name="handle_position">GTK_POS_LEFT</property>
+ <property name="snap_edge">GTK_POS_TOP</property>
+
+ <child>
+ <widget class="GtkToolbar" id="toolbar2">
+ <property name="visible">True</property>
+ <property name="orientation">GTK_ORIENTATION_HORIZONTAL</property>
+ <property name="toolbar_style">GTK_TOOLBAR_BOTH</property>
+ <property name="tooltips">True</property>
+
+ <child>
+ <widget class="GtkButton" id="open_button">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="relief">GTK_RELIEF_NORMAL</property>
+ <signal name="clicked" handler="on_file_open_activate" last_modification_time="Fri, 27 Dec 2002 18:57:38 GMT"/>
+
+ <child>
+ <widget class="GtkHBox" id="hbox1">
+ <property name="visible">True</property>
+ <property name="homogeneous">False</property>
+ <property name="spacing">0</property>
+
+ <child>
+ <widget class="GtkImage" id="image13">
+ <property name="visible">True</property>
+ <property name="stock">gtk-open</property>
+ <property name="icon_size">4</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkLabel" id="label1">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Open</property>
+ <property name="use_underline">False</property>
+ <property name="use_markup">False</property>
+ <property name="justify">GTK_JUSTIFY_LEFT</property>
+ <property name="wrap">False</property>
+ <property name="selectable">False</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkButton" id="preferences_button">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="relief">GTK_RELIEF_NORMAL</property>
+
+ <child>
+ <widget class="GtkHBox" id="hbox2">
+ <property name="visible">True</property>
+ <property name="homogeneous">False</property>
+ <property name="spacing">0</property>
+
+ <child>
+ <widget class="GtkImage" id="image14">
+ <property name="visible">True</property>
+ <property name="stock">gtk-preferences</property>
+ <property name="icon_size">4</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkLabel" id="label2">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Preferences</property>
+ <property name="use_underline">False</property>
+ <property name="use_markup">False</property>
+ <property name="justify">GTK_JUSTIFY_LEFT</property>
+ <property name="wrap">False</property>
+ <property name="selectable">False</property>
+ <property name="xalign">0.5</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ </child>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkScrolledWindow" id="scrolledwindow1">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="hscrollbar_policy">GTK_POLICY_ALWAYS</property>
+ <property name="vscrollbar_policy">GTK_POLICY_ALWAYS</property>
+ <property name="shadow_type">GTK_SHADOW_NONE</property>
+ <property name="window_placement">GTK_CORNER_TOP_LEFT</property>
+
+ <child>
+ <widget class="GtkTreeView" id="treeview">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="headers_visible">False</property>
+ <property name="rules_hint">True</property>
+ <property name="reorderable">False</property>
+ <property name="enable_search">True</property>
+ </widget>
+ </child>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkStatusbar" id="status_bar">
+ <property name="visible">True</property>
+ <property name="has_resize_grip">True</property>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+ </widget>
+ </child>
+</widget>
+
+<widget class="GnomeAbout" id="about_window">
+ <property name="visible">True</property>
+ <property name="destroy_with_parent">False</property>
+ <property name="copyright" translatable="yes">(C) 2002 Jonathan Pryor</property>
+ <property name="comments" translatable="yes">Displays System.Reflection information about .NET types.</property>
+ <property name="authors">Jonathan Pryor</property>
+ <property name="documenters">Jonathan Pryor</property>
+ <property name="translator_credits" translatable="yes">translator_credits</property>
+</widget>
+
+</glade-interface>
--- /dev/null
+<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
+<!DOCTYPE glade-project SYSTEM "http://glade.gnome.org/glade-project-2.0.dtd">
+
+<glade-project>
+ <name>Type Reflector</name>
+ <program_name>type-reflector</program_name>
+ <gnome_support>FALSE</gnome_support>
+</glade-project>
--- /dev/null
+PROGRAM = type-reflector.exe
+
+PROGRAM_LIBS =
+
+PROGRAM_FLAGS = /out:$(PROGRAM) /d:TRACE /d:DEBUG $(PROGRAM_LIBS)
+
+# For debugging
+# CSCFLAGS = /debug+ /debug:full
+CSCFLAGS =
+
+MONO = mono
+
+PROGRAM_FILES = \
+ ConsoleTypeDisplayer.cs \
+ CSharpNodeFormatter.cs \
+ DefaultNodeFormatter.cs \
+ ExplicitNodeFinder.cs \
+ Factories.cs \
+ GroupingNodeFinder.cs \
+ IndentingTextWriter.cs \
+ INodeFinder.cs \
+ INodeFormatter.cs \
+ ITypeDisplayer.cs \
+ LanguageNodeFormatter.cs \
+ Node.cs \
+ NodeFinder.cs \
+ NodeFormatter.cs \
+ NodeGrouper.cs \
+ NodeInfo.cs \
+ NodeTypes.cs \
+ ProgramOptions.cs \
+ ReflectionNodeFinder.cs \
+ TestTypes.cs \
+ TextFormatter.cs \
+ TypeDisplayer.cs \
+ TypeFactory.cs \
+ TypeLoader.cs \
+ TypeReflectorApp.cs \
+ TypeReflectorOptions.cs \
+ VBNodeFormatter.cs \
+
+GUI_GTK_FILES = \
+ gtk/GtkTypeDisplayer.cs \
+
+GUI_GTK_GLADE_FILE = gtk/type-reflector.glade
+
+GUI_GTK_FLAGS = /d:HAVE_GUI_GTK /resource:$(GUI_GTK_GLADE_FILE)
+
+GUI_GTK_LIBS = -r glib-sharp.dll -r pango-sharp.dll -r atk-sharp.dll -r gdk-sharp.dll -r gtk-sharp.dll -r System.Drawing -r glade-sharp.dll
+
+all: $(PROGRAM)
+
+$(PROGRAM) : $(PROGRAM_FILES)
+ $(CSC) $(CSCFLAGS) $(PROGRAM_FLAGS) $(PROGRAM_FILES) $(PROGRAM_LIBS)
+ chmod +x $(PROGRAM)
+
+gui: $(PROGRAM_FILES) $(GUI_GTK_FILES) $(GUI_GTK_GLADE_FILE)
+ $(CSC) $(CSCFLAGS) $(PROGRAM_FLAGS) $(GUI_GTK_FLAGS) $(PROGRAM_FILES) $(GUI_GTK_FILES) $(GUI_GTK_LIBS)
+ chmod +x $(PROGRAM)
+
+test-run : $(PROGRAM)
+ $(MONO) $(PROGRAM) -A $(PROGRAM) $(ARGS)
+
+test-type : $(PROGRAM)
+ $(MONO) $(PROGRAM) -A $(PROGRAM) --max-depth=10000 $(ARGS) TestClass$$
+
+run : $(PROGRAM)
+ $(MONO) $(PROGRAM) $(ARGS)
+
+windows:
+ NAnt -buildfile:type-reflector.build
+
+linux:
+ mcs @unix.args
+
+clean:
+ rm -f *.exe *.pdb *.dll *.dbg *~
+
+INSTALL_FILES = \
+ $(PROGRAM) \
+ $(PROGRAM).config \
+
+
+install: $(PROGRAM) $(PROGRAM).config
+ if test x$$prefix = x; then \
+ echo Usage is: make -f makefile.gnu install prefix=YOURPREFIX; \
+ exit 1; \
+ fi
+ mkdir -p $(prefix)/bin/
+ for i in $(INSTALL_FILES) ; do \
+ ($(INSTALL) -m 755 $$i $(prefix)/bin/) || exit 1; \
+ done
+
+linecount:
+ wc -l $(PROGRAM_FILES) $(GUI_GTK_FILES)
+
--- /dev/null
+INSTALL = /usr/bin/install
+CSC = mcs
+
+include makefile.core
+
<add name="indenter" value="0"/>
<add name="node-finder" value="0"/>
<add name="type-loader" value="0"/>
+ <add name="type-factory" value="0"/>
</switches>
+ <trace>
+ <listeners>
+ <add
+ name="foo"
+ type="System.Diagnostics.TextWriterTraceListener, System"
+ initializeData="debug.txt"/>
+ </listeners>
+ </trace>
</system.diagnostics>
</configuration>