Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Item Property (Type, String)
Collapse the table of content
Expand the table of content

XmlAttributeOverrides.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
Assemblies:   System.Xml (in System.Xml.dll)
  System.Xml.XmlSerializer (in System.Xml.XmlSerializer.dll)

public XmlAttributes 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.

member
Type: System.String

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

Property Value

Type: System.Xml.Serialization.XmlAttributes
An XmlAttributes that represents the collection of overriding attributes.

Use this overload to return an XmlAttributes object that contains objects that override an XmlArrayAttribute, XmlArrayItemAttribute, XmlAttributeAttribute, XmlElementAttribute, or XmlEnumAttribute. If the XmlAttributes object contains an XmlRootAttribute or XmlTypeAttribute, you must use the overload that specifies only the overridden type.

The following example creates an XmlAttributeOverrides object, an XmlAttributes, and an XmlAttributeAttribute object. The example assigns the XmlAttributeAttribute to the XmlAttribute property of the XmlAttributes object and adds the XmlAttributes object to the XmlAttributeOverrides object. Lastly, the example gets the XmlAttributes object by passing the Type of the serialized class and member name to the XmlAttributeOverrides object.

// This is the class that will be serialized. 
public class Group
{
   public string GroupName;
   [XmlAttribute]
   public int GroupCode;
}

public class Sample
{
public XmlSerializer CreateOverrider()
{
   // Create an XmlSerializer with overriding attributes.
   XmlAttributeOverrides xOver = new XmlAttributeOverrides();

   /* Create an XmlAttributeAttribute object and set the 
   AttributeName property. */
   XmlAttributeAttribute xAtt = new XmlAttributeAttribute();
   xAtt.AttributeName = "Code";

   /* Create a new XmlAttributes object and set the 
   XmlAttributeAttribute object to the XmlAttribute property. */
   XmlAttributes attrs = new XmlAttributes();
   attrs.XmlAttribute = xAtt;

   /* Add the XmlAttributes to the XmlAttributeOverrides object. The
   name of the overridden attribute must be specified. */
   xOver.Add(typeof(Group), "GroupCode", attrs);


   // Get the XmlAttributes object for the type and member.
   XmlAttributes tempAttrs;
   tempAttrs = xOver[typeof(Group), "GroupCode"];
   Console.WriteLine(tempAttrs.XmlAttribute.AttributeName);

   // Create the XmlSerializer instance and return it.
   XmlSerializer xSer = new XmlSerializer(typeof(Group), xOver);
   return xSer;
}
}

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone Silverlight 8.1, Windows Phone Silverlight 8

Portable Class Library

Supported in: Portable Class Library
Show:
© 2015 Microsoft