Export (0) Print
Expand All

SoapAttributeOverrides.Item Property (Type, String)

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

Namespace:  System.Xml.Serialization
Assembly:  System.Xml (in System.Xml.dll)

public SoapAttributes this[
	Type type,
	string member
] { get; }

Parameters

type
Type: System.Type
The base class Type that is associated with the collection of attributes you want to override.
member
Type: System.String
The name of the overridden member that specifies the SoapAttributes to return.

Property Value

Type: System.Xml.Serialization.SoapAttributes
A SoapAttributes that represents the collection of overriding attributes.

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.

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.


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

}


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

ADD
Show:
© 2014 Microsoft