Controls how the XmlSerializer serializes an enumeration member.
Assembly: System.Xml (in System.Xml.dll)
Gets or sets the value generated in an XML document when the XmlSerializer serializes an enumeration, or the value recognized when it deserializes the enumeration member.
This API supports the product infrastructure and is not intended to be used directly from your code. Returns a value that indicates whether this instance is equal to a specified object.(Inherited from Attribute.)
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.(Inherited from Object.)
Returns the hash code for this instance.(Inherited from Attribute.)
When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.(Inherited from Attribute.)
When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.(Inherited from Attribute.)
Returns a string that represents the current object.(Inherited from Object.)
|_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)|
Maps a set of names to a corresponding set of dispatch identifiers.(Inherited from Attribute.)
|_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)|
Retrieves the type information for an object, which can be used to get the type information for an interface.(Inherited from Attribute.)
Retrieves the number of type information interfaces that an object provides (either 0 or 1).(Inherited from Attribute.)
|_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)|
Provides access to properties and methods exposed by an object.(Inherited from Attribute.)
The XmlSerializer serializes or deserializes an object as encoded SOAP XML. The resulting XML conforms to section 5 of the World Wide Web Consortium (www.w3.org) document "Simple Object Access Protocol (SOAP) 1.1". For a complete list of similar attributes, see Attributes That Control Encoded SOAP Serialization.class belongs to a family of attributes that controls how the
Use 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 to the enumeration member and set the Name property to "Single".to change the enumeration that the
You can override the Name property value of a by creating an instance of the class and assigning it to the SoapEnum property of a SoapAttributes. For details, see the SoapAttributeOverrides class overview.
You can use the word SoapEnum in your code instead of the longer.
For more information about using attributes, see Extending Metadata Using Attributes.
The following example uses the XmlSerializer to serialize a class named Food that includes an enumeration named FoodType. The FoodType enumeration is overridden by creating a for each enumeration and setting the SoapEnum property of a SoapAttributes to the . The SoapAttributes is added to a SoapAttributeOverrides that is used to create an XmlSerializer.
Imports System Imports System.IO Imports System.Xml Imports System.Xml.Serialization Public Class Group Public GroupName As String Public Grouptype As GroupType End Class Public enum GroupType ' Use the SoapEnumAttribute to instruct the XmlSerializer ' to generate Small and Large instead of A and B. <SoapEnum("Small")> _ A <SoapEnum("Large")> _ B End enum Public Class Run Public Shared Sub Main() Dim test As Run = new Run() test.SerializeObject("SoapEnum.xml") test.SerializeOverride("SoapOverride.xml") Console.WriteLine("Fininished writing two files") End Sub Private Shared Sub SerializeObject(filename As string) ' Create an instance of the XmlSerializer Class. Dim mapp As XmlTypeMapping = _ (New SoapReflectionImporter()).ImportTypeMapping(GetType(Group)) Dim mySerializer As XmlSerializer = New XmlSerializer(mapp) ' Writing the file requires a TextWriter. Dim writer As TextWriter = New StreamWriter(filename) ' Create an instance of the Class that will be serialized. Dim myGroup As Group = New Group() ' Set the object properties. myGroup.GroupName = ".NET" myGroup.Grouptype= GroupType.A ' Serialize the Class, and close the TextWriter. mySerializer.Serialize(writer, myGroup) writer.Close() End Sub Private Sub SerializeOverride(fileName As String) Dim soapOver As SoapAttributeOverrides = new SoapAttributeOverrides() Dim SoapAtts As SoapAttributes = new SoapAttributes() ' Add a SoapEnumAttribute for the GroupType.A enumerator. Instead ' of 'A' it will be "West". Dim soapEnum As SoapEnumAttribute = new SoapEnumAttribute("West") ' Override the "A" enumerator. SoapAtts.SoapEnum = soapEnum soapOver.Add(GetType(GroupType), "A", SoapAtts) ' Add another SoapEnumAttribute for the GroupType.B enumerator. ' Instead of 'B' it will be "East". SoapAtts= New SoapAttributes() soapEnum = new SoapEnumAttribute() soapEnum.Name = "East" SoapAtts.SoapEnum = soapEnum soapOver.Add(GetType(GroupType), "B", SoapAtts) ' Create an XmlSerializer used for overriding. Dim map As XmlTypeMapping = New SoapReflectionImporter _ (soapOver).ImportTypeMapping(GetType(Group)) Dim ser As XmlSerializer = New XmlSerializer(map) Dim myGroup As Group = New Group() myGroup.GroupName = ".NET" myGroup.Grouptype = GroupType.B ' Writing the file requires a TextWriter. Dim writer As TextWriter = New StreamWriter(fileName) ser.Serialize(writer, myGroup) writer.Close End Sub End Class
Available since 1.1
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.