[Mono-list] Question about attributes

xiii29@free.fr xiii29@free.fr
Thu, 29 Apr 2004 08:56:12 +0200


First : Thanks for the explanation ;-)

But my question what about which attributes using in order to document methods 
or function in my code.

For example, if you want the Visual Studio .Net Property Panel to be able to 
display info about your properties you have to use 
System.ComponentModel.Description("The description"). 

This is a Visual Studio .Net rules.

Now my question is : of I want to add documention to my methods, class etc... 
which meta-attributes do I use ? 

Maybe there is no dedicated attributes and I will have to create my owns...

Thierry !

Selon Jonathan Pryor <jonpryor@vt.edu>:

> On Wed, 2004-04-28 at 16:46, Xiii29 wrote:
> > I've question about attributes in Mono. I would like to comment my
> > assemblys by using attributes (meta-attributes...) and i'm wondering if
> > there is "rules" (or preconisations...) about which attributes using...
> I'm pretty sure I don't understand your question at all.  But I'll take
> a shot anyway...
> To use an assembly-level attribute, you need to explicitly specify what
> the attribute is associated with.  For example:
> 	[assembly: AssemblyTitle ("my title")]
> 	[assembly: AssemblyVersion ("1.0.*")]
> The "assembly:" indicates that the attribute applies to the assembly. 
> Otherwise it would apply to the next member listed in the file
> (delegate, class, structure, etc.) or generate an error (namespaces
> don't support attributes).  Similar things can be done for other
> elements; for example: "return:" can be used to place an attribute on
> the return type of a method, while normally the attribute applies to the
> method itself:
> 	[SomeAttribute ("applies to MyMethod")]
> 	[return: SomeAttribute ("applies to the return type")]
> 	int MyMethod () {return 42;}
> As for general rules...  You can only use attributes which can be
> applied to an assembly; that is, the attribute you're trying to use must
> itself have an AttributeUsage attribute with AttributeTargets.Assembly
> specified.  Not all attributes do this; the DllImport attribute, for
> example, can only be applied to methods.
> Aside from that, the normal attribute restrictions apply.  Which means
> that attribute positional and named parameters can only be: one of the
> CLS-compliant built-in types (bool, byte, char, double, float, int,
> long, short, string); System.Type, an enum type; System.Object; or an
> array of one of the previous types.
> See a good C# book, or MSDN, or google, for more information.
>  - Jon