[Mono-dev] monodocer and compier generated types.

Jonathan Pryor jonpryor at vt.edu
Mon Jan 1 08:12:36 EST 2007


On Sun, 2006-12-31 at 16:24 -0500, Miguel de Icaza wrote:
> > I think monodocer (or whoever has generated this file) should
> > ignore classes marked with the CompilerGenerated attribute.
> 
> It seems like recent monodocer versions took care of this (or maybe it
> was an improved scope for the classes generated by mcs/gmcs).

At present, monodocer only ignores internal types.  If a type is public
and has the CompilerGenerated attribute, it will still get documented.

Question: will there ever be a circumstance for a CompilerGenerated type
to be public (aside from someone manually creating such a type, rather
than the compiler doing so)?

If there shouldn't be a public CompilerGenerated type, then this patch
isn't necessary.

> Index: monodocer.cs
> ===================================================================
> --- monodocer.cs        (revision 70266)
> +++ monodocer.cs        (working copy)
> @@ -4,6 +4,8 @@
>  
>  using System;
>  using System.Collections;
> +using System.Runtime.CompilerServices;
> +
>  #if !NET_1_0
>  using System.Collections.Generic;
>  #endif
> @@ -313,6 +315,26 @@
>                 }       
>         }
>  
> +       //
> +       // Returns true if the given type was compiler generated.
> +       //
> +       // In the 1.0 profile we do not have an attribute to check
> +       // for, so we check for the MCS pattern for compiler generated
> +       // types.  This is fragile.
> +       //
> +       public static bool IsCompilerGenerated (Type type)
> +       {
> +#if NET_1_0
> +               string type_name = type.Name;
> +               
> +               if (type_name.IndexOf ("<>c__") != -1)
> +                       return true;
> +               return false;
> +#else
> +               object [] attrs = type.GetCustomAttributes (typeof
> (CompilerGeneratedAttribute), true);
> +               return (attrs.Length > 0);
> +#endif
> +       }
>         
>         public static void DoUpdateNS(string ns, string nspath, string
> outpath) {
>                 Hashtable seenTypes = new Hashtable();
> @@ -342,10 +364,14 @@
>                 
>                 // Stub types not in the directory
>                 foreach (Type type in assembly.GetTypes()) {
> -                       if (type.Namespace == null) continue;
> +                       if (type.Namespace == null)
> +                               continue;

This change is redundant.

Otherwise, the patch looks good, *if* it's necessary.

If it is deemed necessary, you should include a test for it by changing
DocTest-v1.cs and adding a public [CompilerGenerated] type.  It
shouldn't cause any new files to be created (use `svn status DocTest' to
check).

 - Jon





More information about the Mono-devel-list mailing list