SoapEnumAttribute 클래스

정의

XmlSerializer가 열거형 멤버를 serialize하는 방식을 제어합니다.

public ref class SoapEnumAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Field)]
public class SoapEnumAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Field)>]
type SoapEnumAttribute = class
    inherit Attribute
Public Class SoapEnumAttribute
Inherits Attribute
상속
SoapEnumAttribute
특성

예제

다음 예제에서는 명명된 XmlSerializer 열거형을 포함하는 클래스 Food 를 serialize하는 데 FoodType사용합니다. 열거형은 FoodType 각 열거형에 대해 만들고 SoapEnumAttribute a의 속성을 해당 열거형으로 설정 SoapEnum 하여 재정의 SoapAttributes SoapEnumAttribute됩니다. SoapAttributes 에 추가 되는 SoapAttributeOverrides 만드는 데 사용 되는 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 개체를 인코딩된 SOAP XML로 직렬화하거나 역직렬화하는 방법을 XmlSerializer 제어하는 특성 제품군에 속합니다. 결과 XML은 WORLD Wide Web 컨소시엄 문서 SOAP(Simple Object Access Protocol) 1.1의 섹션 5를 준수합니다. 유사한 특성의 전체 목록은 인코딩된 SOAP Serialization을 제어하는 특성을 참조하세요.

개체를 인코딩된 SOAP 메시지로 직렬화하려면 클래스 메서드 SoapReflectionImporterImportTypeMapping 사용하여 만든 항목을 생성 XmlSerializer XmlTypeMapping 해야 합니다.

SoapEnumAttribute 클래스를 각각 직렬화하거나 역직렬화할 때 생성하거나 인식하는 열거 XmlSerializer 형을 변경하는 데 사용합니다. 예를 들어 열거형에 이름이 지정된 One멤버가 포함되어 있지만 XML 출력의 이름을 지정 Single하려면 열거형 멤버에 적용 SoapEnumAttribute 하고 속성을 "Single"로 설정합니다 Name .

클래스의 인스턴스를 Name SoapEnumAttribute 만들고 클래스의 SoapEnumAttribute 속성에 할당하여 속성 값을 재정의SoapAttributesSoapEnum 수 있습니다. 자세한 내용은 클래스 개요를 SoapAttributeOverrides 참조하세요.

개체를 인코딩된 SOAP 메시지로 직렬화하려면 클래스 메서드 SoapReflectionImporterImportTypeMapping 사용하여 만든 항목을 생성 XmlSerializer XmlTypeMapping 해야 합니다.

참고

더 긴 SoapEnumAttribute대신 코드에서 단어를 SoapEnum 사용할 수 있습니다.

특성을 사용 하는 방법에 대 한 자세한 내용은 참조 하세요. 특성합니다.

생성자

SoapEnumAttribute()

SoapEnumAttribute 클래스의 새 인스턴스를 초기화합니다.

SoapEnumAttribute(String)

지정된 요소 이름을 사용하여 SoapEnumAttribute 클래스의 새 인스턴스를 초기화합니다.

속성

Name

XmlSerializer가 열거형을 serialize할 때 XML 문서에서 생성된 값 또는 열거형 멤버를 역직렬화할 때 인식된 값을 가져오거나 설정합니다.

TypeId

파생 클래스에서 구현된 경우 이 Attribute에 대한 고유 식별자를 가져옵니다.

(다음에서 상속됨 Attribute)

메서드

Equals(Object)

이 인스턴스가 지정된 개체와 같은지를 나타내는 값을 반환합니다.

(다음에서 상속됨 Attribute)
GetHashCode()

이 인스턴스의 해시 코드를 반환합니다.

(다음에서 상속됨 Attribute)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
IsDefaultAttribute()

파생 클래스에서 재정의된 경우 이 인스턴스 값이 파생 클래스에 대한 기본값인지 여부를 표시합니다.

(다음에서 상속됨 Attribute)
Match(Object)

파생 클래스에서 재정의된 경우 이 인스턴스가 지정된 개체와 같은지 여부를 나타내는 값을 반환합니다.

(다음에서 상속됨 Attribute)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

명시적 인터페이스 구현

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

이름 집합을 해당하는 디스패치 식별자 집합에 매핑합니다.

(다음에서 상속됨 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

인터페이스의 형식 정보를 가져오는 데 사용할 수 있는 개체의 형식 정보를 검색합니다.

(다음에서 상속됨 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

개체에서 제공하는 형식 정보 인터페이스의 수를 검색합니다(0 또는 1).

(다음에서 상속됨 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

개체에서 노출하는 메서드와 속성에 대한 액세스를 제공합니다.

(다음에서 상속됨 Attribute)

적용 대상