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 msdn.microsoft.com/library/system.attribute.aspx. 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.
| Attribute | Purpose |
XmlArray | Indicates the name that should be given to an array in an XML serialization. |
XmlArrayItem | Indicates a type that can be in an array in an XML serialization. |
XmlAttribute | Indicates 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. |
XmlElement | Specifically indicates the field will be serialized as an XML element. This attribute allows you to change the XML element’s name. |
XmlEnum | Enables you to specify the names by which enumeration values are serialized. |
XmlIgnore | Indicates that an XML serialization should not ... |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access