次の方法で共有


SoapAttributeOverrides.Item プロパティ

オーバーライドする側の SOAP 属性のコレクションを表すオブジェクトを取得します。

[C#] C# では、このプロパティは SoapAttributeOverrides クラスのインデクサになります。

オーバーロードの一覧

指定された型 (基本クラス) に関連付けられているオブジェクトを取得します。

[Visual Basic] Overloads Public Default ReadOnly Property Item(Type) As SoapAttributes

[C#] public SoapAttributes this[Type] {get;}

[C++] public: __property SoapAttributes* get_Item(Type*);

[JScript] SoapAttributeOverrides.Item (Type)

指定された型 (基本クラス) に関連付けられているオブジェクトを取得します。member パラメータには、オーバーライドされる基本クラス メンバを指定します。

[Visual Basic] Overloads Public Default ReadOnly Property Item(Type, String) As SoapAttributes

[C#] public SoapAttributes this[Type, string] {get;}

[C++] public: __property SoapAttributes* get_Item(Type*, String*);

[JScript] SoapAttributeOverrides.Item (Type, String)

使用例

[Visual Basic, C#, C++] Group クラスのインスタンスのシリアル化をオーバーライドするために使用される SoapAttributeOverrides の作成例を次に示します。この例では、 Item プロパティを使用して、シリアル化のオーバーライドを指定するために使用される SoapAttributes の取得も行っています。

[Visual Basic, C#, C++] メモ   ここでは、Item プロパティ (SoapAttributeOverrides インデクサ) のオーバーロード形式のうちの 1 つだけについて、使用例を示します。その他の例については、各オーバーロード形式のトピックを参照してください。

 
Imports System
Imports System.IO
Imports System.Xml
Imports System.Xml.Serialization

Public Class Group
   ' Override the serialization of this member. 
   Public GroupName As String 
End Class

Public Class Run

   Shared Sub Main()

      Dim test As Run = new Run()

      test.SerializeOverride("GetSoapAttributesVB.xml")
      
   End Sub
   
   Public Sub SerializeOverride(filename As string )
      ' Create an instance of the XmlSerializer class
      ' that overrides the serialization.
      Dim overrideSerializer As XmlSerializer = _
      CreateOverrideSerializer()

      ' 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"

      ' Serialize the class, and close the TextWriter.
      overrideSerializer.Serialize(writer, myGroup)
       writer.Close()
   End Sub

   Private Function CreateOverrideSerializer() As XmlSerializer 
   
      Dim mySoapAttributeOverrides As SoapAttributeOverrides  = _
      New SoapAttributeOverrides()
      Dim mySoapAtts As SoapAttributes = new SoapAttributes()

      Dim mySoapElement As SoapElementAttribute = _
      new SoapElementAttribute()
      mySoapElement.ElementName = "TeamName"
      mySoapAtts.SoapElement = mySoapElement
      ' Add the SoapAttributes to the 
      ' mySoapAttributeOverridesrides object.
      mySoapAttributeOverrides.Add(GetType(Group), "GroupName", _
      mySoapAtts)
      ' Get the SoapAttributes with the Item property.
      Dim thisSoapAtts As SoapAttributes = _
      mySoapAttributeOverrides(GetType(Group), "GroupName")
      Console.WriteLine("New serialized element name: " & _
      thisSoapAtts.SoapElement.ElementName)

      ' Create an XmlTypeMapping that is used to create an instance 
      ' of the XmlSerializer. Then return the XmlSerializer object.
      Dim myMapping As XmlTypeMapping = _
      (New SoapReflectionImporter(mySoapAttributeOverrides)). _
      ImportTypeMapping(GetType(Group))
    
      Dim ser As XmlSerializer = new XmlSerializer(myMapping)
      return ser
   End Function

End Class

[C#] 
using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;

public class Group
{
   // Override the serialization of this member. 
   public string GroupName;
}
  
public class Run
{
   public static void Main()
   {
      Run test = new Run();

      test.SerializeOverride("GetSoapAttributes.xml");
      
   }
   public void SerializeOverride(string filename)
   {
      // Create an instance of the XmlSerializer class
      // that overrides the serialization.
      XmlSerializer overRideSerializer = CreateOverrideSerializer();

      // 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";

      // Serialize the class, and close the TextWriter.
      overRideSerializer.Serialize(writer, myGroup);
       writer.Close();
   }

   private XmlSerializer CreateOverrideSerializer()
   {
      SoapAttributeOverrides mySoapAttributeOverrides = 
      new SoapAttributeOverrides();
      SoapAttributes mySoapAttributes = new SoapAttributes();

      SoapElementAttribute mySoapElement = new SoapElementAttribute();
      mySoapElement.ElementName = "TeamName";
      mySoapAttributes.SoapElement = mySoapElement;
      // Add the SoapAttributes to the 
      // mySoapAttributeOverridesrides object.
      mySoapAttributeOverrides.Add(typeof(Group), "GroupName", 
      mySoapAttributes);
      // Get the SoapAttributes with the Item property.
      SoapAttributes thisSoapAtts = 
      mySoapAttributeOverrides[typeof(Group), "GroupName"];
      Console.WriteLine("New serialized element name: " + 
      thisSoapAtts.SoapElement.ElementName);

      // Create an XmlTypeMapping that is used to create an instance 
      // of the XmlSerializer. Then return the XmlSerializer object.
      XmlTypeMapping myMapping = (new SoapReflectionImporter(
      mySoapAttributeOverrides)).ImportTypeMapping(typeof(Group));
    
      XmlSerializer ser = new XmlSerializer(myMapping);
      return ser;
   }

}

[C++] 
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;
using namespace System::Xml::Serialization;

__gc public class Group 
{
public:
   // Override the serialization of this member. 
   String* GroupName;
};

__gc public class Run 
{
public:
   void SerializeOverride(String* filename) 
   {
      // Create an instance of the XmlSerializer class
      // that overrides the serialization.
      XmlSerializer * overRideSerializer = CreateOverrideSerializer();

      // 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 = S".NET";

      // Serialize the class, and close the TextWriter.
      overRideSerializer -> Serialize(writer, myGroup);
      writer -> Close();
   }

private:
   XmlSerializer * CreateOverrideSerializer() 
   {
      SoapAttributeOverrides* mySoapAttributeOverrides = new SoapAttributeOverrides();
      SoapAttributes* mySoapAttributes = new SoapAttributes();

      SoapElementAttribute* mySoapElement = new SoapElementAttribute();
      mySoapElement -> ElementName = S"TeamName";
      mySoapAttributes -> SoapElement = mySoapElement;

      // Add the SoapAttributes to the 
      // mySoapAttributeOverridesrides object.
      mySoapAttributeOverrides -> Add(__typeof(Group), S"GroupName", mySoapAttributes);

      // Get the SoapAttributes with the Item property.
      SoapAttributes * thisSoapAtts = mySoapAttributeOverrides->get_Item(__typeof(Group), S"GroupName");
      Console::WriteLine(S"New serialized element name: {0}", thisSoapAtts -> SoapElement -> ElementName);

      // Create an XmlTypeMapping that is used to create an instance 
      // of the XmlSerializer. Then return the XmlSerializer object.
      XmlTypeMapping * myMapping = (new SoapReflectionImporter(mySoapAttributeOverrides)) -> ImportTypeMapping(__typeof(Group));

      XmlSerializer* ser = new XmlSerializer(myMapping);
      return ser;
   }
};

int main() 
{
   Run* test = new Run();
   test -> SerializeOverride(S"GetSoapAttributes.xml");
}

[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

参照

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