Click here to Skip to main content
15,885,244 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
I have a quick question about Attributes

When we use the Description attribute we normaly do it like this
[Description("Class that contains information about an user")]
public class user
But how come we can construct the type like Description("") and DescriptionAttribute("") ???
i mean, i can't seem to find the class called Description, when i look with the object browser, but the DescriptionAttribute is there.[confused][confused]

I have been looking on MSDN, but nothing seems to popup about this.

Anyone have a answer [D'Oh] [D'Oh]
Posted
Updated 20-Feb-13 0:13am
v3

From MSDN (http://msdn.microsoft.com/en-us/library/bfz783fz.aspx):

"By convention, all attribute names end with Attribute. However, several languages that target the runtime, such as Visual Basic and C#, do not require you to specify the full name of an attribute. For example, if you want to initialize System..::.ObsoleteAttribute, you only need to reference it as Obsolete."

 
Share this answer
 
stuff surrounded by "[" and "]" are not normal classes. They are class attributes and can be used hundreds of different ways...

Look here for more info: http://www.codeproject.com/KB/cs/attributes.aspx[^]

 
Share this answer
 
Hello Paw,

* I can see that the question is 5 years old ;) , but I've just happened to read it now...

See DescriptionAttribute Class
on MSDN
[^]

You can see this CP article on Attributes in C# in general (it's a little old but it's ok):
Attributes in C#[^]

Cheers,
Edo
 
Share this answer
 
Comments
Paw Jershauge 20-Feb-13 6:16am    
Thanks Edo. ;) It's been solved... ;)
But still thanks for the reply on this also ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900