[Mono-list] Enhancements to type-reflector

Jonathan Pryor jonpryor@vt.edu
02 Sep 2002 11:36:45 -0400


Incredible.  I put the source into CVS last night, and I'm already
getting patches. :-)

To answer your questions, it both compiles and works under Mono.  Not
always as well as I'd like: --output=reflection doesn't work under Mono,
and other parts cause exceptions under Mono (grep for ShowMonoBroken and
MONO_BROKEN in the source).  However, it works reasonably well under
Mono at the moment, and I've found it useful for uncovering Mono runtime
(which I need to enter into bugzilla, such as the behavior of the "x"
format specifier on enumerations, which doesn't work reliably).

However, regarding your patch, I don't like it long-term, mostly as it
special-cases a lot of Attribute classes.  Ideally, I would use
reflection on the attribute, and display the values of all public
properties and fields, similar in spirit to:

	[MyAttribute(Foo="a", Bar="b", Baz=42, Qux=MyEnum.Quux)]

The downside is that this wouldn't necessarily be valid C# source code. 
Some properties are read-only, as their value is set by positional
parameters.  Other constructor values might not be available through
properties, so these would be missing.

However, the above mechanism would allow for all Properties to be
displayed, and presents enough information to be useful.  It is also
generic, and doesn't require special casing for each possible attribute
type.

There are two problems with this solution, however: (1) it isn't written
yet (on my todo list), and (2) it would require reflection, the same
uses as --output=reflection.  This doesn't work as desired under Mono at
present, but I hope that it will work properly soon.

Thanks,
 - Jon

On Mon, 2002-09-02 at 10:07, Steinar Herland wrote:
> I made some changes to the
> mcs/tools/type-reflector/CSharpTypeDisplayer.cs (only tested using
> MS.NET)
> 
> - Does this also compile / work on mono?
> - Sorry - I haven't figured out (yet) how to do a diff against the cvs.
> If this change is ok, can someone please commit the changes I made?
> 
> After the changes type-reflector.exe prints more complete attribute
> constructors:
> 
> $ type-reflector.exe --output=c# DataColumn
> 
> returns:
> 
> [System.ComponentModel.DefaultPropertyAttribute("ColumnName")]
> [System.ComponentModel.ToolboxItemAttribute("")]
> [System.Reflection.DefaultMemberAttribute("Item")]
> [System.ComponentModel.DesignTimeVisibleAttribute]
> [System.ComponentModel.EditorAttribute("Microsoft.VSDesigner.Data.Design
> .DataColumnEditor", "System.Drawing.Design.UITypeEditor")]
> [System.ComponentModel.DesignerAttribute("System.Windows.Forms.Design.Co
> mponentDocumentDesigner", "System.ComponentModel.Design.IRootDesigner")]
> [System.ComponentModel.DesignerCategoryAttribute("Component")]
> [System.ComponentModel.TypeConverterAttribute("System.ComponentModel.Com
> ponentConverter")]
> class      System.Data.DataColumn
>   {
>   }
>  .
> .
>  .
> 
> 
> Steinar
>