SoapAttributeOverrides.Item[] Eigenschaft

Definition

Ruft ein Objekt ab, das die Auflistung der überschreibenden SOAP-Attribute darstellt.

Überlädt

Item[Type]

Ruft das dem angegebenen (Basisklassen-)Typ zugeordnete Objekt ab.

Item[Type, String]

Ruft das dem angegebenen (Basisklassen-)Typ zugeordnete Objekt ab. Durch den member-Parameter wird der zu überschreibende Member der Basisklasse angegeben.

Item[Type]

Ruft das dem angegebenen (Basisklassen-)Typ zugeordnete Objekt ab.

public:
 property System::Xml::Serialization::SoapAttributes ^ default[Type ^] { System::Xml::Serialization::SoapAttributes ^ get(Type ^ type); };
public System.Xml.Serialization.SoapAttributes? this[Type type] { get; }
public System.Xml.Serialization.SoapAttributes this[Type type] { get; }
member this.Item(Type) : System.Xml.Serialization.SoapAttributes
Default Public ReadOnly Property Item(type As Type) As SoapAttributes

Parameter

type
Type

Die Type-Basisklasse, die der Auflistung der abzurufenden Attribute zugeordnet ist.

Eigenschaftswert

SoapAttributes

Ein SoapAttributes, das die Auflistung der überschreibenden Attribute darstellt.

Beispiele

Im folgenden Beispiel wird ein SoapAttributeOverrides Objekt erstellt, das verwendet wird, um die Serialisierung einer Instanz der Group Klasse außer Kraft zu setzen. Im Beispiel wird auch die Eigenschaft verwendet, um die Item[] SoapAttributes Eigenschaft abzurufen, die verwendet wird, um anzugeben, wie die Serialisierung außer Kraft gesetzt wird.

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

using namespace System;
using namespace System::IO;
using namespace System::Xml;
using namespace System::Xml::Serialization;

// The name of this type will be overridden using
// the SoapTypeAttribute.
public ref class Group
{
public:
   String^ GroupName;
};

public ref 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 = gcnew StreamWriter( filename );

      // Create an instance of the class that will be serialized.
      Group^ myGroup = gcnew 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 = gcnew SoapAttributeOverrides;
      SoapAttributes^ mySoapAttributes = gcnew SoapAttributes;
      SoapTypeAttribute^ mySoapType = gcnew SoapTypeAttribute;
      mySoapType->TypeName = "Team";
      mySoapAttributes->SoapType = mySoapType;

      // Add the SoapAttributes to the 
      // mySoapAttributeOverridesrides object.
      mySoapAttributeOverrides->Add( Group::typeid, mySoapAttributes );

      // Get the SoapAttributes with the Item property.
      SoapAttributes^ thisSoapAtts = mySoapAttributeOverrides[ Group::typeid ];
      Console::WriteLine( "New serialized type name: {0}", thisSoapAtts->SoapType->TypeName );

      // Create an XmlTypeMapping that is used to create an instance 
      // of the XmlSerializer. Then return the XmlSerializer object.
      XmlTypeMapping^ myMapping = (gcnew SoapReflectionImporter( mySoapAttributeOverrides ))->
            ImportTypeMapping( Group::typeid );
      XmlSerializer^ ser = gcnew XmlSerializer( myMapping );
      return ser;
   }
};

int main()
{
   Run^ test = gcnew Run;
   test->SerializeOverride( "GetSoapAttributes2.xml" );
}
using System;
using System.IO;
using System.Xml;
using System.Xml.Serialization;

// The name of this type will be overridden using
// the SoapTypeAttribute.
public class Group
{
   public string GroupName;
}

public class Run
{
   public static void Main()
   {
      Run test = new Run();

      test.SerializeOverride("GetSoapAttributes2.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();

      SoapTypeAttribute mySoapType = new SoapTypeAttribute();
      mySoapType.TypeName= "Team";
      mySoapAttributes.SoapType = mySoapType;
      // Add the SoapAttributes to the
      // mySoapAttributeOverridesrides object.
      mySoapAttributeOverrides.Add(typeof(Group), mySoapAttributes);
      // Get the SoapAttributes with the Item property.
      SoapAttributes thisSoapAtts =
      mySoapAttributeOverrides[typeof(Group)];
      Console.WriteLine("New serialized type name: " +
      thisSoapAtts.SoapType.TypeName);

      // 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;
   }
}
Imports System.IO
Imports System.Xml
Imports System.Xml.Serialization

' The name of this type will be overridden using
' the SoapTypeAttribute.
Public Class Group
   Public GroupName As String 
End Class

Public Class Run

   Shared Sub Main()

      Dim test As Run = new Run()

      test.SerializeOverride("GetSoapAttributesVB2.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 mySoapType As SoapTypeAttribute = _
      new SoapTypeAttribute()
      mySoapType.TypeName = "Team"
      mySoapAtts.SoapType = mySoapType
      ' Add the SoapAttributes to the 
      ' mySoapAttributeOverridesrides object.
      mySoapAttributeOverrides.Add(GetType(Group), mySoapAtts)

      ' Get the SoapAttributes with the Item property.
      Dim thisSoapAtts As SoapAttributes = _
      mySoapAttributeOverrides(GetType(Group))
      Console.WriteLine("New serialized type name: " & _
      thisSoapAtts.SoapType.TypeName)

      ' 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

Hinweise

Verwenden Sie diese Überladung, um ein SoapAttributes Attribut zurückzugeben, das Attribute für eine SoapTypeAttribute.

Gilt für

Item[Type, String]

Ruft das dem angegebenen (Basisklassen-)Typ zugeordnete Objekt ab. Durch den member-Parameter wird der zu überschreibende Member der Basisklasse angegeben.

public:
 property System::Xml::Serialization::SoapAttributes ^ default[Type ^, System::String ^] { System::Xml::Serialization::SoapAttributes ^ get(Type ^ type, System::String ^ member); };
public System.Xml.Serialization.SoapAttributes? this[Type type, string member] { get; }
public System.Xml.Serialization.SoapAttributes this[Type type, string member] { get; }
member this.Item(Type * string) : System.Xml.Serialization.SoapAttributes
Default Public ReadOnly Property Item(type As Type, member As String) As SoapAttributes

Parameter

type
Type

Der Type der Basisklasse, der der Auflistung der zu überschreibenden Attribute zugeordnet ist.

member
String

Der Name des überschriebenen Member, der das zurückzugebende SoapAttributes angibt.

Eigenschaftswert

SoapAttributes

Ein SoapAttributes, das die Auflistung der überschreibenden Attribute darstellt.

Beispiele

Im folgenden Beispiel wird eine SoapAttributeOverrides Verwendung zum Außerkraftsetzen der Serialisierung einer Instanz der Group Klasse erstellt. Im Beispiel wird auch die Eigenschaft verwendet, um die Item[] SoapAttributes Eigenschaft abzurufen, die verwendet wird, um anzugeben, wie die Serialisierung außer Kraft gesetzt wird.

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

using namespace System;
using namespace System::IO;
using namespace System::Xml;
using namespace System::Xml::Serialization;

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

public ref 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 = gcnew StreamWriter( filename );

      // Create an instance of the class that will be serialized.
      Group^ myGroup = gcnew 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 = gcnew SoapAttributeOverrides;
      SoapAttributes^ mySoapAttributes = gcnew SoapAttributes;
      SoapElementAttribute^ mySoapElement = gcnew SoapElementAttribute;
      mySoapElement->ElementName = "TeamName";
      mySoapAttributes->SoapElement = mySoapElement;

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

      // Get the SoapAttributes with the Item property.
      SoapAttributes^ thisSoapAtts = mySoapAttributeOverrides[Group::typeid, "GroupName"];
      Console::WriteLine( "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 = (gcnew SoapReflectionImporter( mySoapAttributeOverrides ))->
            ImportTypeMapping( Group::typeid );
      XmlSerializer^ ser = gcnew XmlSerializer( myMapping );

      return ser;
   }
};

int main()
{
   Run^ test = gcnew Run;
   test->SerializeOverride( "GetSoapAttributes.xml" );
}
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;
   }
}
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

Hinweise

Verwenden Sie diese Überladung, um ein SoapAttributes Attribut zurückzugeben, das Attribute überschreiben, die einen SoapAttributeAttribute, SoapElementAttribute, SoapIgnoreAttributeoder SoapEnumAttribute. Sie können auch einen SoapAttributes Wert zurückgeben, der die Außerkraftsetzung eines Standardwerts enthält, der eine DefaultValueAttribute.

Wenn dies SoapAttributes eine SoapTypeAttributeenthält, müssen Sie die Überladung verwenden, die nur den überschriebenen Typ angibt.

Gilt für