- What is .NET Metadata?
- Attributes Everywhere You Turn
- System.Reflection.Attribute
- Your First Attribute
- Interrogating Your Metadata
- Wrapping It Up
- References
Attributes Everywhere You Turn
Although assembly and type metadata are important for the CLR to function, attributes are just special .NET types that contain data that is stored with the assembly and types. Throughout the .NET Framework, attributes are used to describe different ancillary information or behaviors of classes. For example, .NET serialization uses the Serializable and NonSerialized attributes to specify that a class can be serialized, as well as what members not to serialize:
[Serializable] public class MySpecialClass { // Serializable since the class is // marked with the Serializable attribute public string dataOne; public string dataTwo; public string dataThree; public string dataFour; // Not serializable since we marked it [NonSerialized] public string dataFive; }
But what exactly are attributes? Peering into the System.Reflection.Attribute class will help answer that question.