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.
People have already covered the UI aspect – attributes have other uses, though… for example, they are used extensively in most serialization frameworks. Some attributes are given special treatment by the compiler – for example,
[PrincipalPermission(...)]adds declarative security to a method, allowing you to (automatically) check that the user has suitable access.To add your own special handling, you can use PostSharp; there are many great examples of using PostSharp to do AOP things, like logging – or just code simplification, such as with automatic
INotifyPropertyChangedimplementation.