SoapEnumAttribute クラス
アセンブリ: System.Xml (system.xml.dll 内)

<AttributeUsageAttribute(AttributeTargets.Field)> _ Public Class SoapEnumAttribute Inherits Attribute
[AttributeUsageAttribute(AttributeTargets::Field)] public ref class SoapEnumAttribute : public Attribute

SoapEnumAttribute クラスは、XmlSerializer がオブジェクトをエンコード済み SOAP XML としてシリアル化または逆シリアル化する方法を制御する一連の属性のうちの 1 つです。結果として生成される XML は、W3C (World Wide Web Consortium) (www.w3.org) のドキュメント『Simple Object Access Protocol (SOAP) 1.1』のセクション 5 に準拠します。類似する属性の完全な一覧については、「エンコード済み SOAP シリアル化を制御する属性」を参照してください。
オブジェクトをエンコード済み SOAP メッセージとしてシリアル化するには、SoapReflectionImporter クラスの ImportTypeMapping メソッドで作成された XmlTypeMapping を使用して、XmlSerializer を構築する必要があります。
XmlSerializer が生成する (クラスをシリアル化する場合) または認識する (クラスを逆シリアル化する場合) 列挙体を変更するには、SoapEnumAttribute を使用します。たとえば、One という名前のメンバが含まれている列挙体の XML 出力の名前を Single にする場合は、SoapEnumAttribute をその列挙体メンバに適用し、Name プロパティを "Single" に設定します。
SoapEnumAttribute の Name プロパティ値をオーバーライドするには、SoapEnumAttribute クラスのインスタンスを作成し、それを SoapAttributes の SoapEnum プロパティに割り当てます。詳細については、SoapAttributeOverrides クラスの概要を参照してください。
オブジェクトをエンコード済み SOAP メッセージとしてシリアル化するには、SoapReflectionImporter クラスの ImportTypeMapping メソッドで作成された XmlTypeMapping を使用して、XmlSerializer を構築する必要があります。
![]() |
---|

XmlSerializer を使用して、FoodType という名前の列挙体を含んでいる Food という名前のクラスをシリアル化する例を次に示します。各列挙体の SoapEnumAttribute を作成し、該当する SoapEnumAttribute を SoapAttributes の SoapEnum プロパティに設定することにより、FoodType 列挙体をオーバーライドしています。この SoapAttributes が、XmlSerializer を作成するために使用される SoapAttributeOverrides に追加されます。
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
using System; using System.IO; using System.Xml; using System.Xml.Serialization; public class Group{ public string GroupName; public GroupType Grouptype; } 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 } public class Run { static void Main(){ Run test= new Run(); test.SerializeObject("SoapEnum.xml"); test.SerializeOverride("SoapOverride.xml"); Console.WriteLine("Fininished writing two files"); } private void SerializeObject(string filename){ // Create an instance of the XmlSerializer Class. XmlTypeMapping mapp = (new SoapReflectionImporter()).ImportTypeMapping(typeof(Group)); XmlSerializer mySerializer = new XmlSerializer(mapp); // Writing the file requires a TextWriter. TextWriter writer = new StreamWriter(filename); // Create an instance of the Class that will be serialized. Group myGroup = 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(); } private void SerializeOverride(string fileName){ SoapAttributeOverrides soapOver = new SoapAttributeOverrides(); SoapAttributes SoapAtts = new SoapAttributes(); // Add a SoapEnumAttribute for the GroupType.A enumerator. // Instead of 'A' it will be "West". SoapEnumAttribute soapEnum = new SoapEnumAttribute("West"); // Override the "A" enumerator. SoapAtts.SoapEnum = soapEnum; soapOver.Add(typeof(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(typeof(GroupType), "B", SoapAtts); // Create an XmlSerializer used for overriding. XmlTypeMapping map = new SoapReflectionImporter(soapOver). ImportTypeMapping(typeof(Group)); XmlSerializer ser = new XmlSerializer(map); Group myGroup = new Group(); myGroup.GroupName = ".NET"; myGroup.Grouptype = GroupType.B; // Writing the file requires a TextWriter. TextWriter writer = new StreamWriter(fileName); ser.Serialize(writer, myGroup); writer.Close(); } }
import System.*; import System.IO.*; import System.Xml.*; import System.Xml.Serialization.*; public class Group { public String groupName; public GroupType groupType; } //Group public class GroupType { // Use the SoapEnumAttribute to instruct the XmlSerializer // to generate Small and Large instead of a and b. public int member; public GroupType() { member = 0; } //GroupType public GroupType(int n) { member = n; } //GroupType /** @attribute SoapEnum("Small") */ public static int a = 0; /** @attribute SoapEnum("Large") */ public static int b = 1; } //GroupType public class Run { public static void main(String[] args) { Run test = new Run(); test.SerializeObject("SoapEnum.xml"); test.SerializeOverride("SoapOverride.xml"); Console.WriteLine("Fininished writing two files"); } //main private void SerializeObject(String fileName) { // Writing the file requires a TextWriter. TextWriter writer = new StreamWriter(fileName); // Create an instance of the Class that will be serialized. Group myGroup = new Group(); // Set the object properties. myGroup.groupName = ".NET"; myGroup.groupType = new GroupType(GroupType.a); // Create an instance of the XmlSerializer Class. XmlSerializer mySerializer = new XmlSerializer(myGroup.GetType()); // Serialize the Class, and close the TextWriter. mySerializer.Serialize(writer, myGroup); writer.Close(); } //SerializeObject private void SerializeOverride(String fileName) { SoapAttributeOverrides soapOver = new SoapAttributeOverrides(); SoapAttributes SoapAtts = new SoapAttributes(); // Add a SoapEnumAttribute for the GroupType.a enumerator. // Instead of 'a' it will be "West". SoapEnumAttribute soapEnum = new SoapEnumAttribute("West"); // Override the "a" enumerator. SoapAtts.set_SoapEnum(soapEnum); soapOver.Add(GroupType.class.ToType(), "a", SoapAtts); // Add another SoapEnumAttribute for the GroupType.b enumerator. // Instead of b it will be "East". SoapAtts = new SoapAttributes(); soapEnum = new SoapEnumAttribute(); soapEnum.set_Name("East"); SoapAtts.set_SoapEnum(soapEnum); soapOver.Add(GroupType.class.ToType(), "b", SoapAtts); // Create an XmlSerializer used for overriding. Group myGroup = new Group(); myGroup.groupName = ".NET"; myGroup.groupType = new GroupType(GroupType.b); // Writing the file requires a TextWriter. TextWriter writer = new StreamWriter(fileName); XmlSerializer ser = new XmlSerializer(myGroup.GetType()); ser.Serialize(writer, myGroup); writer.Close(); } //SerializeOverride } //Run

System.Attribute
System.Xml.Serialization.SoapEnumAttribute


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
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- SoapEnumAttribute クラスのページへのリンク