SoapEnumAttribute SoapEnumAttribute SoapEnumAttribute SoapEnumAttribute Class

定義

XmlSerializer が列挙体メンバーをシリアル化する方法を制御します。Controls how the XmlSerializer serializes an enumeration member.

public ref class SoapEnumAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Field)]
public class SoapEnumAttribute : Attribute
type SoapEnumAttribute = class
    inherit Attribute
Public Class SoapEnumAttribute
Inherits Attribute
継承
SoapEnumAttributeSoapEnumAttributeSoapEnumAttributeSoapEnumAttribute
属性

次の例では、XmlSerializerという名前のクラスをシリアル化するFoodという名前の列挙を含むFoodTypeします。The following example uses the XmlSerializer to serialize a class named Food that includes an enumeration named FoodType. FoodType列挙型の変更を作成、SoapEnumAttributeの各列挙と設定、SoapEnumのプロパティをSoapAttributesSoapEnumAttributeします。The FoodType enumeration is overridden by creating a SoapEnumAttribute for each enumeration and setting the SoapEnum property of a SoapAttributes to the SoapEnumAttribute. SoapAttributesに追加されます、SoapAttributeOverrides作成に使用される、XmlSerializerします。The SoapAttributes is added to a SoapAttributeOverrides that is used to create an XmlSerializer.

#using <System.Xml.dll>
#using <System.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
using namespace System::Xml::Serialization;
public enum class 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 ref class Group
{
public:
   String^ GroupName;
   GroupType Grouptype;
};

public ref class Run
{
public:
   void SerializeObject( String^ filename )
   {
      // Create an instance of the XmlSerializer Class.
      XmlTypeMapping^ mapp = (gcnew SoapReflectionImporter)->ImportTypeMapping( Group::typeid );
      XmlSerializer^ mySerializer = gcnew XmlSerializer( mapp );

      // Writing the file requires a TextWriter.
      TextWriter^ writer = gcnew StreamWriter( filename );

      // Create an instance of the Class that will be serialized.
      Group^ myGroup = gcnew 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();
   }

   void SerializeOverride( String^ fileName )
   {
      SoapAttributeOverrides^ soapOver = gcnew SoapAttributeOverrides;
      SoapAttributes^ SoapAtts = gcnew SoapAttributes;

      // Add a SoapEnumAttribute for the GroupType::A enumerator.       
      // Instead of 'A'  it will be S"West".
      SoapEnumAttribute^ soapEnum = gcnew SoapEnumAttribute( "West" );

      // Override the S"A" enumerator.
      SoapAtts->GroupType::SoapEnum = soapEnum;
      soapOver->Add( GroupType::typeid, "A", SoapAtts );

      // Add another SoapEnumAttribute for the GroupType::B enumerator.
      // Instead of //B// it will be S"East".
      SoapAtts = gcnew SoapAttributes;
      soapEnum = gcnew SoapEnumAttribute;
      soapEnum->Name = "East";
      SoapAtts->GroupType::SoapEnum = soapEnum;
      soapOver->Add( GroupType::typeid, "B", SoapAtts );

      // Create an XmlSerializer used for overriding.
      XmlTypeMapping^ map = (gcnew SoapReflectionImporter( soapOver ))->ImportTypeMapping( Group::typeid );
      XmlSerializer^ ser = gcnew XmlSerializer( map );
      Group^ myGroup = gcnew Group;
      myGroup->GroupName = ".NET";
      myGroup->Grouptype = GroupType::B;

      // Writing the file requires a TextWriter.
      TextWriter^ writer = gcnew StreamWriter( fileName );
      ser->Serialize( writer, myGroup );
      writer->Close();
   }
};

int main()
{
   Run^ test = gcnew Run;
   test->SerializeObject( "SoapEnum.xml" );
   test->SerializeOverride( "SoapOverride.xml" );
   Console::WriteLine( "Fininished writing two files" );
}
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();
   	}
}
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

注釈

SoapEnumAttributeを制御する属性のファミリに属しているクラスが、どのXmlSerializerをシリアル化またはエンコードされた SOAP XML としてオブジェクトを逆シリアル化します。The SoapEnumAttribute class belongs to a family of attributes that controls how the XmlSerializer serializes or deserializes an object as encoded SOAP XML. 結果の XML は World Wide Web Consortium のドキュメントのセクション 5 に準拠している簡易オブジェクト アクセス プロトコル (SOAP) 1.1します。The resulting XML conforms to section 5 of the World Wide Web Consortium document Simple Object Access Protocol (SOAP) 1.1. 類似の属性の完全な一覧を参照してください。 Attributes That Control Encoded SOAP Serializationします。For a complete list of similar attributes, see Attributes That Control Encoded SOAP Serialization.

エンコードされた SOAP メッセージとしてオブジェクトをシリアル化、構築する必要があります、XmlSerializerを使用して、XmlTypeMappingで作成された、ImportTypeMappingのメソッド、SoapReflectionImporterクラス。To serialize an object as an encoded SOAP message, you must construct the XmlSerializer using an XmlTypeMapping created with the ImportTypeMapping method of the SoapReflectionImporter class.

使用、SoapEnumAttribute列挙体を変更するが、 XmlSerializer (シリアル化または、それぞれ、クラスを逆シリアル化) ときに認識または生成します。Use the SoapEnumAttribute to change the enumeration that the XmlSerializer generates or recognizes (when it serializes or deserializes a class, respectively). 列挙体には、という名前のメンバーが含まれている場合の例のOne、XML 出力の名前を使用するが、 Single、適用、SoapEnumAttributeに列挙型のメンバーを設定し、Nameプロパティを「単一」にします。For example, if an enumeration contains a member named One, but you prefer that the XML output be named Single, apply the SoapEnumAttribute to the enumeration member and set the Name property to "Single".

オーバーライドすることができます、Nameプロパティの値をSoapEnumAttributeのインスタンスを作成して、SoapEnumAttributeクラスとに割り当てること、SoapEnumのプロパティをSoapAttributesします。You can override the Name property value of a SoapEnumAttribute by creating an instance of the SoapEnumAttribute class and assigning it to the SoapEnum property of a SoapAttributes. 詳細については、次を参照してください。、SoapAttributeOverridesクラスの概要。For details, see the SoapAttributeOverrides class overview.

エンコードされた SOAP メッセージとしてオブジェクトをシリアル化、構築する必要があります、XmlSerializerを使用して、XmlTypeMappingで作成された、ImportTypeMappingのメソッド、SoapReflectionImporterクラス。To serialize an object as an encoded SOAP message, you must construct the XmlSerializer using an XmlTypeMapping created with the ImportTypeMapping method of the SoapReflectionImporter class.

注意

語を使用できますSoapEnum代わりに、コードでSoapEnumAttributeします。You can use the word SoapEnum in your code instead of the longer SoapEnumAttribute.

属性の使用方法の詳細については、次を参照してください。属性します。For more information about using attributes, see Attributes.

コンストラクター

SoapEnumAttribute() SoapEnumAttribute() SoapEnumAttribute() SoapEnumAttribute()

SoapEnumAttribute クラスの新しいインスタンスを初期化します。Initializes a new instance of the SoapEnumAttribute class.

SoapEnumAttribute(String) SoapEnumAttribute(String) SoapEnumAttribute(String) SoapEnumAttribute(String)

要素名を指定して、SoapEnumAttribute クラスの新しいインスタンスを初期化します。Initializes a new instance of the SoapEnumAttribute class using the specified element name.

プロパティ

Name Name Name Name

XmlSerializer が列挙体をシリアル化する場合は XML ドキュメントに生成された値を、列挙体メンバーを逆シリアル化する場合には認識した値を、取得または設定します。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.

TypeId TypeId TypeId TypeId

派生クラスで実装されると、この Attribute の一意の識別子を取得します。When implemented in a derived class, gets a unique identifier for this Attribute.

(Inherited from Attribute)

メソッド

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

このインスタンスが、指定されたオブジェクトと等価であるかどうかを示す値を返します。Returns a value that indicates whether this instance is equal to a specified object.

(Inherited from Attribute)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

このインスタンスのハッシュ コードを返します。Returns the hash code for this instance.

(Inherited from Attribute)
GetType() GetType() GetType() GetType()

現在のインスタンスの Type を取得します。Gets the Type of the current instance.

(Inherited from Object)
IsDefaultAttribute() IsDefaultAttribute() IsDefaultAttribute() IsDefaultAttribute()

派生クラスでオーバーライドされるとき、このインスタンスの値が派生クラスの既定値であるかどうかを示します。When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(Inherited from Attribute)
Match(Object) Match(Object) Match(Object) Match(Object)

派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(Inherited from Attribute)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

現在の Object の簡易コピーを作成します。Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

現在のオブジェクトを表す文字列を返します。Returns a string that represents the current object.

(Inherited from Object)

明示的なインターフェイスの実装

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) _Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) _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) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _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)
_Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32)

オブジェクトが提供する型情報インターフェイスの数 (0 または 1) を取得します。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) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

オブジェクトによって公開されたプロパティおよびメソッドへのアクセスを提供します。Provides access to properties and methods exposed by an object.

(Inherited from Attribute)

適用対象