Export (0) Print
Expand All
0 out of 1 rated this helpful - Rate this topic

XmlEnumAttribute Class

Controls how the XmlSerializer serializes an enumeration member.

Namespace: System.Xml.Serialization
Assembly: System.Xml (in system.xml.dll)

[AttributeUsageAttribute(AttributeTargets.Field)] 
public class XmlEnumAttribute : Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Field) */ 
public class XmlEnumAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Field) 
public class XmlEnumAttribute extends Attribute

The XmlEnumAttribute belongs to a family of attributes that controls how the XmlSerializer serializes or deserializes an object. For a complete list of similar attributes, see Attributes That Control XML Serialization.

Use the XmlEnumAttribute to change the enumeration that the XmlSerializer generates or recognizes (when it serializes or deserializes a class, respectively). For example, if an enumeration contains a member named One, but you prefer that the XML output be named Single, apply the XmlEnumAttribute to the enumeration member and set the Name property to "Single".

You can override the Name property value of an XmlEnumAttribute by creating an instance of the XmlEnumAttribute class and assigning it to the XmlEnum property of an XmlAttributes object. For details, see the XmlAttributeOverrides class.

NoteNote

You can use the word XmlEnum in your code instead of the longer XmlEnumAttribute.

The following example applies the XmlEnumAttribute to the members of an enumeration. When the XmlSerializer generates XML data for this enumeration, the data conforms to the values of the Name properties.

public enum EmployeeStatus
{
   [XmlEnum(Name = "Single")]
   One,
   [XmlEnum(Name = "Double")]
   Two,
   [XmlEnum(Name = "Triple")]
   Three
}
   

public class EmployeeStatus
{
    /** @attribute XmlEnum(Name = "Single")
     */
    public static int one;
    /** @attribute XmlEnum(Name = "Double")
     */
    public static int two;
    /** @attribute XmlEnum(Name = "Triple")
     */
    public static int three;
} //EmployeeStatus

NoteNote

You can use the word XmlEnum in your code instead of the longer XmlEnumAttribute.

System.Object
   System.Attribute
    System.Xml.Serialization.XmlEnumAttribute
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.