Appendix G Useful Attributes

The .NET Framework defines more than 500 attribute classes, so only a handful of the most commonly used are described here.

The names of attribute classes end with Attribute. If you want to search for an attribute’s class, add Attribute to the end of the name. For example, the ReadOnly attribute class’s name is ReadOnlyAttribute.

To create a custom attribute, simply create a new class derived from the Attribute class. By convention, the custom attribute class’s name should end with Attribute.

For more information about attributes, see If you scroll to the bottom, you can see a list of classes that inherit from the Attribute class.

Useful XML Serialization Attributes

The following table lists attributes that are useful when performing XML serializations.

XmlArrayIndicates the name that should be given to an array in an XML serialization.
XmlArrayItemIndicates a type that can be in an array in an XML serialization.
XmlAttributeIndicates that a property should be serialized as an attribute rather than an element in an XML serialization. Optionally indicates the attribute’s name in the serialization.
XmlElementSpecifically indicates the field will be serialized as an XML element. This attribute allows you to change the XML element’s name.
XmlEnumEnables you to specify the names by which enumeration values are serialized.
XmlIgnoreIndicates that an XML serialization should not ...

Get C# 5.0 Programmer's Reference now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.