SoapAttributeOverrides.Item[] Property

Definition

Gets an object that represents the collection of overriding SOAP attributes.

Overloads

Item[Type]

Gets the object associated with the specified (base class) type.

Item[Type, String]

Gets the object associated with the specified (base class) type. The member parameter specifies the base class member that is overridden.

Item[Type]

Source:
SoapAttributeOverrides.cs
Source:
SoapAttributeOverrides.cs
Source:
SoapAttributeOverrides.cs

Gets the object associated with the specified (base class) type.

C#
public System.Xml.Serialization.SoapAttributes? this[Type type] { get; }
C#
public System.Xml.Serialization.SoapAttributes this[Type type] { get; }

Parameters

type
Type

The base class Type that is associated with the collection of attributes you want to retrieve.

Property Value

A SoapAttributes that represents the collection of overriding attributes.

Examples

The following example creates a SoapAttributeOverrides that is used to override the serialization of an instance of the Group class. The example also uses the Item[] property to retrieve the SoapAttributes that is used to specify how the serialization is being overridden.

C#
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;
   }
}

Remarks

Use this overload to return a SoapAttributes that contains attributes for a SoapTypeAttribute.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1

Item[Type, String]

Source:
SoapAttributeOverrides.cs
Source:
SoapAttributeOverrides.cs
Source:
SoapAttributeOverrides.cs

Gets the object associated with the specified (base class) type. The member parameter specifies the base class member that is overridden.

C#
public System.Xml.Serialization.SoapAttributes? this[Type type, string member] { get; }
C#
public System.Xml.Serialization.SoapAttributes this[Type type, string member] { get; }

Parameters

type
Type

The base class Type that is associated with the collection of attributes you want to override.

member
String

The name of the overridden member that specifies the SoapAttributes to return.

Property Value

A SoapAttributes that represents the collection of overriding attributes.

Examples

The following example creates a SoapAttributeOverrides used to override the serialization of an instance of the Group class. The example also uses the Item[] property to retrieve the SoapAttributes that is used to specify how the serialization is being overridden.

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;
   }
}

Remarks

Use this overload to return a SoapAttributes that contains attributes that override a SoapAttributeAttribute, SoapElementAttribute, SoapIgnoreAttribute, or SoapEnumAttribute. You can also return a SoapAttributes that contains the override of a default value that uses a DefaultValueAttribute.

If the SoapAttributes contains a SoapTypeAttribute, you must use the overload that specifies only the overridden type.

Applies to

.NET 10 and other versions
Product Versions
.NET Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0, 2.1