Allow greater control of property generation by derived classes (through
authorJonathan Pryor <jpryor@novell.com>
Sat, 11 Jan 2003 04:42:20 +0000 (04:42 -0000)
committerJonathan Pryor <jpryor@novell.com>
Sat, 11 Jan 2003 04:42:20 +0000 (04:42 -0000)
PropertyFormat properties).

Fix a bug where the ReflectionNodeFinder wouldn't display the value of static
properties (it was using an invalid instance reference).

svn path=/trunk/mcs/; revision=10372

mcs/tools/type-reflector/CSharpNodeFormatter.cs
mcs/tools/type-reflector/LanguageNodeFormatter.cs
mcs/tools/type-reflector/ReflectionNodeFinder.cs
mcs/tools/type-reflector/VBNodeFormatter.cs
mcs/tools/type-reflector/finders/ReflectionNodeFinder.cs
mcs/tools/type-reflector/formatters/CSharpNodeFormatter.cs
mcs/tools/type-reflector/formatters/LanguageNodeFormatter.cs
mcs/tools/type-reflector/formatters/VBNodeFormatter.cs

index dfb602d12000ce372dd8e34f8fcddbb8e58bf5e4..84ccff257127abf59b7d99bfc307c1d49dbbcbde 100644 (file)
@@ -24,6 +24,10 @@ namespace Mono.TypeReflector.Formatters
 
                protected override string LineComment       {get {return "//";}}
 
+               protected override string PropertyFormat    {get {return "{0} {1} {{{2}{3}}}";}}
+               protected override string PropertyGetFormat {get {return "get{0};";}}
+               protected override string PropertySet       {get {return "set;";}}
+
                protected override string KeywordClass      {get {return "class";}}
                protected override string KeywordEnum       {get {return "enum";}}
                protected override string KeywordValueType  {get {return "struct";}}
index de5dd0b1f047b27f9da0fd05c242d3976bf9d89c..42b5e2f22f1fc5e92cce14ca46f31cc7362eece4 100644 (file)
@@ -24,6 +24,21 @@ namespace Mono.TypeReflector.Formatters
                // [0] is open, [1] is close
                protected abstract string[] AttributeDelimeters {get;}
 
+               // Format for Property descriptions generated by GetPropertyDescription
+               // {0}: Property Type
+               // {1}: Property Name
+               // {2}: The Get Accessor.  This will be generated from PropertyGetFormat,
+               //                      if appropriate.
+               // {3}: The Set Accessor.  This will be generated from PropertySet, if
+               //                      appropriate
+               protected abstract string PropertyFormat {get;}
+
+               // Format for the `get' property accessor
+               // {0}: The return value of the property, if present
+               protected abstract string PropertyGetFormat {get;}
+
+               protected abstract string PropertySet {get;}
+
                protected abstract string KeywordClass {get;}
                protected abstract string KeywordEnum {get;}
                protected abstract string KeywordValueType {get;}
@@ -310,19 +325,22 @@ namespace Mono.TypeReflector.Formatters
                        AddAttributes (sb, property);
                        AddMethodQualifiers (sb, property.GetAccessors(true)[0]);
 
-                       sb.AppendFormat ("{0} {1} {{", property.PropertyType, property.Name);
+                       string getter = null;
                        if (property.CanRead) {
-                               sb.Append ("get");
+                               string v = null;
                                try {
-                                       sb.AppendFormat (" /* = {0} */", GetValue (property.GetValue (instance, null)));
+                                       v = string.Format (" /* = {0} */", GetValue (property.GetValue (instance, null)));
                                }
                                catch {
                                }
-                               sb.Append (";");
+                               getter = string.Format (PropertyGetFormat, v);
                        }
+
+                       string setter = null;
                        if (property.CanWrite)
-                               sb.Append ("set;");
-                       sb.Append ("}}");
+                               setter = PropertySet;
+
+                       sb.AppendFormat (PropertyFormat, property.PropertyType, property.Name, getter, setter);
 
                        return sb.ToString();
                }
index afb19fc79f70ce45bc4d29522691a7bd132b6a60..3795811bbcdbf7f60eb57131787a2860114e5778 100644 (file)
@@ -55,8 +55,10 @@ namespace Mono.TypeReflector.Finders
 
                protected override void AddTypeChildren (NodeInfoCollection c, NodeInfo parent, Type type)
                {
+                       object instance = parent.ReflectionInstance;
+
                        foreach (MemberInfo mi in GetMembers (type)) {
-                               AddNode (c, parent, mi, mi);
+                               AddNode (c, parent, mi, instance);
                        }
                }
 
index cbc3f6ca8f1f0d4c92dc1127018abc0a73286b13..26f25e77e906e69125202018e1ea400c80db7e0c 100644 (file)
@@ -24,6 +24,10 @@ namespace Mono.TypeReflector.Formatters
 
                protected override string LineComment       {get {return "'";}}
 
+               protected override string PropertyFormat    {get {return "Property {1} As {0}\n{2}{3}End Property";}}
+               protected override string PropertyGetFormat {get {return "\tGet\n\t\t' Return {0}\n\tEnd Get\n";}}
+               protected override string PropertySet       {get {return "\tSet\n\tEnd Set\n";}}
+
                protected override string KeywordClass      {get {return "Class";}}
                protected override string KeywordEnum       {get {return "Enum";}}
                protected override string KeywordValueType  {get {return "Struct";}}
index afb19fc79f70ce45bc4d29522691a7bd132b6a60..3795811bbcdbf7f60eb57131787a2860114e5778 100644 (file)
@@ -55,8 +55,10 @@ namespace Mono.TypeReflector.Finders
 
                protected override void AddTypeChildren (NodeInfoCollection c, NodeInfo parent, Type type)
                {
+                       object instance = parent.ReflectionInstance;
+
                        foreach (MemberInfo mi in GetMembers (type)) {
-                               AddNode (c, parent, mi, mi);
+                               AddNode (c, parent, mi, instance);
                        }
                }
 
index dfb602d12000ce372dd8e34f8fcddbb8e58bf5e4..84ccff257127abf59b7d99bfc307c1d49dbbcbde 100644 (file)
@@ -24,6 +24,10 @@ namespace Mono.TypeReflector.Formatters
 
                protected override string LineComment       {get {return "//";}}
 
+               protected override string PropertyFormat    {get {return "{0} {1} {{{2}{3}}}";}}
+               protected override string PropertyGetFormat {get {return "get{0};";}}
+               protected override string PropertySet       {get {return "set;";}}
+
                protected override string KeywordClass      {get {return "class";}}
                protected override string KeywordEnum       {get {return "enum";}}
                protected override string KeywordValueType  {get {return "struct";}}
index de5dd0b1f047b27f9da0fd05c242d3976bf9d89c..42b5e2f22f1fc5e92cce14ca46f31cc7362eece4 100644 (file)
@@ -24,6 +24,21 @@ namespace Mono.TypeReflector.Formatters
                // [0] is open, [1] is close
                protected abstract string[] AttributeDelimeters {get;}
 
+               // Format for Property descriptions generated by GetPropertyDescription
+               // {0}: Property Type
+               // {1}: Property Name
+               // {2}: The Get Accessor.  This will be generated from PropertyGetFormat,
+               //                      if appropriate.
+               // {3}: The Set Accessor.  This will be generated from PropertySet, if
+               //                      appropriate
+               protected abstract string PropertyFormat {get;}
+
+               // Format for the `get' property accessor
+               // {0}: The return value of the property, if present
+               protected abstract string PropertyGetFormat {get;}
+
+               protected abstract string PropertySet {get;}
+
                protected abstract string KeywordClass {get;}
                protected abstract string KeywordEnum {get;}
                protected abstract string KeywordValueType {get;}
@@ -310,19 +325,22 @@ namespace Mono.TypeReflector.Formatters
                        AddAttributes (sb, property);
                        AddMethodQualifiers (sb, property.GetAccessors(true)[0]);
 
-                       sb.AppendFormat ("{0} {1} {{", property.PropertyType, property.Name);
+                       string getter = null;
                        if (property.CanRead) {
-                               sb.Append ("get");
+                               string v = null;
                                try {
-                                       sb.AppendFormat (" /* = {0} */", GetValue (property.GetValue (instance, null)));
+                                       v = string.Format (" /* = {0} */", GetValue (property.GetValue (instance, null)));
                                }
                                catch {
                                }
-                               sb.Append (";");
+                               getter = string.Format (PropertyGetFormat, v);
                        }
+
+                       string setter = null;
                        if (property.CanWrite)
-                               sb.Append ("set;");
-                       sb.Append ("}}");
+                               setter = PropertySet;
+
+                       sb.AppendFormat (PropertyFormat, property.PropertyType, property.Name, getter, setter);
 
                        return sb.ToString();
                }
index cbc3f6ca8f1f0d4c92dc1127018abc0a73286b13..26f25e77e906e69125202018e1ea400c80db7e0c 100644 (file)
@@ -24,6 +24,10 @@ namespace Mono.TypeReflector.Formatters
 
                protected override string LineComment       {get {return "'";}}
 
+               protected override string PropertyFormat    {get {return "Property {1} As {0}\n{2}{3}End Property";}}
+               protected override string PropertyGetFormat {get {return "\tGet\n\t\t' Return {0}\n\tEnd Get\n";}}
+               protected override string PropertySet       {get {return "\tSet\n\tEnd Set\n";}}
+
                protected override string KeywordClass      {get {return "Class";}}
                protected override string KeywordEnum       {get {return "Enum";}}
                protected override string KeywordValueType  {get {return "Struct";}}