次の方法で共有


SoapAttributeOverrides.Item プロパティ (Type, String)

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

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

Overloads Public Default ReadOnly Property Item( _
   ByVal type As Type, _   ByVal member As String _) As SoapAttributes
[C#]
public SoapAttributes this[Typetype,stringmember] {get;}
[C++]
public: __property SoapAttributes* get_Item(Type* type,String* member);
[JScript]
returnValue = SoapAttributeOverridesObject.Item(type, member);またはreturnValue = SoapAttributeOverridesObject(type, member);

[JScript] JScript では、この型で定義されている既定のインデックス プロパティを使用することができます。しかし、独自のインデックス プロパティを明示的に定義することはできません。ただし、このクラスの expando 属性を指定すると、既定のインデックス プロパティが提供されます。提供されるインデックス プロパティの型は Object 型であり、インデックス型は String になります。

引数 [JScript]

  • type
    オーバーライドする対象の属性のコレクションに関連付けられている基本クラスのクラス Type
  • member
    返す SoapAttributes を指定する、オーバーライドされたメンバの名前。

パラメータ [Visual Basic, C#, C++]

  • type
    オーバーライドする対象の属性のコレクションに関連付けられている基本クラスのクラス Type
  • member
    返す SoapAttributes を指定する、オーバーライドされたメンバの名前。

プロパティ値

オーバーライドする側の属性のコレクションを表す SoapAttributes

解説

SoapAttributeAttributeSoapElementAttributeSoapIgnoreAttribute 、または SoapEnumAttribute をオーバーライドする属性を格納している SoapAttributes を返すには、このオーバーロードを使用します。 DefaultValueAttribute を使用して指定された既定値のオーバーライドを含む SoapAttributes を返すこともできます。

SoapAttributesSoapTypeAttribute が格納されている場合は、オーバーライドされた型だけを指定するオーバーロードを使用する必要があります。

使用例

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

 
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++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ

参照

SoapAttributeOverrides クラス | SoapAttributeOverrides メンバ | System.Xml.Serialization 名前空間 | SoapAttributeOverrides.Item オーバーロードの一覧