Know the answer? Post it. Somebody with the same question will find it here.
VulpesRank #55 · 29.2K reputationPosted Aug 12, 2011, 6:25 AM EDT
✓ Accepted answer0
Basically, attributes provide information to the compiler, runtime or programmer about the entity on which the attribute is placed. The entity can be a type, a type member, the return value of a function, a parameter of a sub/function or the assembly itself.
Attribute information can be recovered at runtime using reflection.
The .NET Framework provides a number of attributes which have special meanings. For example:
when applied to a class indicates that an object of the class can be serialized.
when applied to a method indicates that the method is a managed proxy for calling an unmanaged method, typically written in C/C++, within a certain dll.
can be applied to various entities and indicates that the entity is compliant with the Common Language Specification (CLS) and can therefore be freely used from any other .NET language.
when applied to a class in LINQ to SQL means that the class is associated with a database table.
means that the entity to which it is applied is now considered obsolete and you should use something else instead.
Attributes are classes which derive from the System.Attribute class.
You can also write your own custom attributes and specify how they are used and which entities they target using the AttributeUsage and AtributeTargets attributes.
For more information, check out the recommended articles on attributes listed to the right of this thread.
VulpesRank #55 · 29.2K reputationPosted Aug 12, 2011, 6:25 AM EDT
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts