SoapEnumAttributeとは? わかりやすく解説

SoapEnumAttribute クラス

XmlSerializer が列挙メンバシリアル化する方法制御します

名前空間: System.Xml.Serialization
アセンブリ: System.Xml (system.xml.dll 内)
構文構文

<AttributeUsageAttribute(AttributeTargets.Field)> _
Public Class SoapEnumAttribute
    Inherits Attribute
Dim instance As SoapEnumAttribute
[AttributeUsageAttribute(AttributeTargets.Field)] 
public class SoapEnumAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Field)] 
public ref class SoapEnumAttribute : public
 Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Field) */ 
public class SoapEnumAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Field) 
public class SoapEnumAttribute extends
 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" に設定します

SoapEnumAttributeName プロパティ値をオーバーライドするには、SoapEnumAttribute クラスインスタンス作成し、それを SoapAttributes の SoapEnum プロパティ割り当てます詳細については、SoapAttributeOverrides クラス概要参照してください

オブジェクトエンコード済み SOAP メッセージとしてシリアル化するには、SoapReflectionImporter クラスImportTypeMapping メソッド作成されXmlTypeMapping使用してXmlSerializer構築する必要があります

メモメモ

コードでは、SoapEnumAttribute代わりに SoapEnum という短い語を使用できます

属性使用方法については、「属性使用したメタデータ拡張」を参照してください

使用例使用例

XmlSerializer使用してFoodType という名前の列挙体を含んでいる Food という名前のクラスシリアル化する例を次に示します。各列挙体の SoapEnumAttribute作成し該当する SoapEnumAttributeSoapAttributesSoapEnum プロパティ設定することにより、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.Object
   System.Attribute
    System.Xml.Serialization.SoapEnumAttribute
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
SoapEnumAttribute メンバ
System.Xml.Serialization 名前空間

SoapEnumAttribute コンストラクタ ()

SoapEnumAttribute クラス新しインスタンス初期化します。

名前空間: System.Xml.Serialization
アセンブリ: System.Xml (system.xml.dll 内)
構文構文

Dim instance As New SoapEnumAttribute
public SoapEnumAttribute ()
public:
SoapEnumAttribute ()
public SoapEnumAttribute ()
public function SoapEnumAttribute ()
解説解説

既存列挙体をオーバーライドするには、SoapEnumAttribute使用します新しSoapEnumAttribute作成しプロパティ設定し、このオブジェクトを SoapAttributes の SoapEnum プロパティ代入ます。列挙体のメンバごとに、新しSoapAttributes作成し、それを SoapAttributeOverrides に追加する必要があります詳細については、SoapAttributeOverrides クラス概要参照してください

メモメモ

コードでは、SoapEnumAttribute代わりに SoapEnum という短い語を使用できます

使用例使用例

XmlSerializer を使用してFoodType という名前の列挙体を含んでいる Food という名前のクラスシリアル化する例を次に示します。各列挙体の SoapEnumAttribute作成し該当する SoapEnumAttributeSoapAttributesSoapEnum プロパティ設定することにより、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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
SoapEnumAttribute クラス
SoapEnumAttribute メンバ
System.Xml.Serialization 名前空間

SoapEnumAttribute コンストラクタ (String)

要素名を指定して、SoapEnumAttribute クラス新しインスタンス初期化します。

名前空間: System.Xml.Serialization
アセンブリ: System.Xml (system.xml.dll 内)
構文構文

Dim name As String

Dim instance As New SoapEnumAttribute(name)
public SoapEnumAttribute (
    string name
)
public:
SoapEnumAttribute (
    String^ name
)
public SoapEnumAttribute (
    String name
)
public function SoapEnumAttribute (
    name : String
)

パラメータ

name

XmlSerializer によって生成される XML 要素名。

解説解説

生成されXML 列挙子を、元の列挙体の列挙子と区別する場合には、Name指定します

メモメモ

コードでは、SoapEnumAttribute代わりに SoapEnum という短い語を使用できます

使用例使用例

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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
SoapEnumAttribute クラス
SoapEnumAttribute メンバ
System.Xml.Serialization 名前空間

SoapEnumAttribute コンストラクタ

SoapEnumAttribute クラス新しインスタンス初期化します。
オーバーロードの一覧オーバーロードの一覧

参照参照

関連項目

SoapEnumAttribute クラス
SoapEnumAttribute メンバ
System.Xml.Serialization 名前空間

SoapEnumAttribute プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ .NET Compact Framework によるサポート TypeId  派生クラス実装されている場合は、この Attribute一意識別子取得します。 ( Attribute から継承されます。)
参照参照

関連項目

SoapEnumAttribute クラス
System.Xml.Serialization 名前空間

SoapEnumAttribute メソッド


パブリック メソッドパブリック メソッド

( プロテクト メソッド参照)
  名前 説明
パブリック メソッド Equals  オーバーロードされます。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttribute  オーバーロードされますアセンブリモジュール、型のメンバ、またはメソッド パラメータ適用され指定した型のカスタム属性取得します。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttributes  オーバーロードされますアセンブリモジュール、型のメンバ、またはメソッド パラメータ適用されカスタム属性配列取得します。 ( Attribute から継承されます。)
パブリック メソッド GetHashCode  このインスタンスハッシュ コード返します。 ( Attribute から継承されます。)
パブリック メソッド GetType  現在のインスタンスType取得します。 ( Object から継承されます。)
パブリック メソッド IsDefaultAttribute  派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラス既定値かどうか示します。 ( Attribute から継承されます。)
パブリック メソッド IsDefined  オーバーロードされます指定した型のカスタム属性が、アセンブリモジュール、型のメンバ、またはメソッド パラメータ適用されているかどうか判断します。 ( Attribute から継承されます。)
パブリック メソッド Match  派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンス等しかどうかを示す値を返します。 ( Attribute から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数Object インスタンス同一かどうか判断します。 ( Object から継承されます。)
パブリック メソッド ToString  現在の Object を表す String返します。 ( Object から継承されます。)
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

SoapEnumAttribute クラス
System.Xml.Serialization 名前空間

SoapEnumAttribute メンバ

XmlSerializer が列挙メンバシリアル化する方法制御します

SoapEnumAttribute データ型公開されるメンバを以下の表に示します


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド SoapEnumAttribute オーバーロードされます。 SoapEnumAttribute クラス新しインスタンス初期化します。
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ .NET Compact Framework によるサポート TypeId  派生クラス実装されている場合は、この Attribute一意識別子取得します。(Attribute から継承されます。)
パブリック メソッドパブリック メソッド
( プロテクト メソッド参照)
  名前 説明
パブリック メソッド Equals  オーバーロードされます。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttribute  オーバーロードされますアセンブリモジュール、型のメンバ、またはメソッド パラメータ適用され指定した型のカスタム属性取得します。 (Attribute から継承されます。)
パブリック メソッド GetCustomAttributes  オーバーロードされますアセンブリモジュール、型のメンバ、またはメソッド パラメータ適用されカスタム属性配列取得します。 (Attribute から継承されます。)
パブリック メソッド GetHashCode  このインスタンスハッシュ コード返します。 (Attribute から継承されます。)
パブリック メソッド GetType  現在のインスタンスType取得します。 (Object から継承されます。)
パブリック メソッド IsDefaultAttribute  派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラス既定値かどうか示します。 (Attribute から継承されます。)
パブリック メソッド IsDefined  オーバーロードされます指定した型のカスタム属性が、アセンブリモジュール、型のメンバ、またはメソッド パラメータ適用されているかどうか判断します。 (Attribute から継承されます。)
パブリック メソッド Match  派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンス等しかどうかを示す値を返します。 (Attribute から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数Object インスタンス同一かどうか判断します。 (Object から継承されます。)
パブリック メソッド ToString  現在の Object を表す String返します。 (Object から継承されます。)
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

SoapEnumAttribute クラス
System.Xml.Serialization 名前空間



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「SoapEnumAttribute」の関連用語

SoapEnumAttributeのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



SoapEnumAttributeのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS