Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# property attributes

I have seen the following code:

[DefaultValue(100)]
[Description("Some descriptive field here")]
public int MyProperty{...} 

The functionality from the above snippit seems clear enough, I have no idea as to how I can use it to do useful things. Im not even sure as to what name to give it!

Does anyone know where I can find more information/a tutorial on these property attributes? I would be also interested in any novel / useful tasks this feature can do.

like image 788
TK. Avatar asked Oct 16 '08 14:10

TK.


1 Answers

The functionality from the above snippit seems clear enough,

Maybe not, as many people think that [DefaultValue()] sets the value of the property. Actually, all it does to tell some visual designer (e.g. Visual Studio), what the code is going to set the default value to. That way it knows to bold the value in the Property Window if it's set to something else.

like image 153
James Curran Avatar answered Oct 26 '22 23:10

James Curran