O'Reilly logo

C# 5.0 Programmer's Reference by Rod Stephens

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

AttributePurpose
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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required