Allan,
When I first started doing C#, I didn't really see the value of attributes
right off the bat either. Once you start using them though, you may begin to
wonder how you ever managed without them.
There are so many uses for attributes, it's hard to even begin listing them,
but here are a few quick ones:
1: Generic access to class data - I have a project on SourceForge
(
http://dotnetdallib.sourceforge.net) that is a data access library. Using
attributes that specify the relationship of data classes to the underlying
database, I'm able to generate dynamic SQL statements to populate data
objects from the database or to write data objects to the database.
2: Similar to 1, attributes can be used to modify the behavior of
serialization of classes using the binary or xml serialization. And there
are actually quite a few other places in .NET where attributes are used to
modify how data is handled.
3: They're used extensively in custom controls to define how the controls
interact with the property grid and other aspects of the IDE.
4: They're can be used as a form of inline documentation (such as the
Obsolete attribute)
If you check the documentation:
ms-help://MS.VSCC.2003/MS.MSDNQTR.2004JAN.1033/cpref/html/frlrfsystemattribu
teclasshierarchy.htm
You'll see that there are a great number of classes derived from
System.Attribute. That alone should hint at how useful they are.
Pete
"A.M" <IH*******@sapm123.com> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Hi,
I am trying to grasp a better underestanding of C# Attributes . I don't
see them as a very usefull capability.
Could anyone refer me to resources show me best practices and how can I
improve my code using attributes?
Thanks,
Allan