A question about attribute

T

Tony Johansson

Hello!

I have two questions about attribute.


If you want to associate an attribute with a class you put the attribute
just before the class definition.
Like this
[myAttribute()]
public class myClass
{//some code here }

I know that it's possible to associate an attribute with an assembly.
But if you want to associate an attribute with an assembly where do you put
the attribute then?


My second question about attribute is it the same if I write the attribute
like this
[myAttribute()]
or
like this
[myAttribute]

//Tony
 
J

Jon Skeet [C# MVP]

Tony Johansson said:
If you want to associate an attribute with a class you put the attribute
just before the class definition.
Like this
[myAttribute()]
public class myClass
{//some code here }

I know that it's possible to associate an attribute with an assembly.
But if you want to associate an attribute with an assembly where do you put
the attribute then?

It doesn't matter - you just need to use "assembly:" appropriately. See
the autogenerated AssemblyInfo.cs file for examples.
My second question about attribute is it the same if I write the attribute
like this
[myAttribute()]
or
like this
[myAttribute]

Yes. The brackets are really only needed when you're specifying
arguments/properties.
 
A

Alvin Bruney [MVP]

Yes. The brackets are really only needed when you're specifying
arguments/properties.
and so is the attribute part of the term for C#
ex. [myattribute] can be written as [my]
--
________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------


Jon Skeet said:
Tony Johansson said:
If you want to associate an attribute with a class you put the attribute
just before the class definition.
Like this
[myAttribute()]
public class myClass
{//some code here }

I know that it's possible to associate an attribute with an assembly.
But if you want to associate an attribute with an assembly where do you
put
the attribute then?

It doesn't matter - you just need to use "assembly:" appropriately. See
the autogenerated AssemblyInfo.cs file for examples.
My second question about attribute is it the same if I write the
attribute
like this
[myAttribute()]
or
like this
[myAttribute]

Yes. The brackets are really only needed when you're specifying
arguments/properties.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top