XmlAttributeOverrides.Item[Type, String] XmlAttributeOverrides.Item[Type, String] XmlAttributeOverrides.Item[Type, String] XmlAttributeOverrides.Item[Type, String] Property

Definition

Überlädt

Item[Type] Item[Type] Item[Type] Item[Type]

Ruft das dem angegebenen Basisklassentyp zugeordnete Objekt ab.Gets the object associated with the specified, base-class, type.

Item[Type, String] Item[Type, String] Item[Type, String] Item[Type, String]

Ruft das dem angegebenen (Basisklassen-)Typ zugeordnete Objekt ab.Gets the object associated with the specified (base-class) type. Durch den member-Parameter wird der zu überschreibende Member der Basisklasse angegeben.The member parameter specifies the base-class member that is overridden.

Item[Type] Item[Type] Item[Type] Item[Type]

Ruft das dem angegebenen Basisklassentyp zugeordnete Objekt ab.Gets the object associated with the specified, base-class, type.

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

Parameter

type
Type Type Type Type

Die Type-Basisklasse, die der Auflistung der abzurufenden Attribute zugeordnet ist.The base class Type that is associated with the collection of attributes you want to retrieve.

Eigenschaftswert

Ein XmlAttributes, das die Auflistung der überschreibenden Attribute darstellt.An XmlAttributes that represents the collection of overriding attributes.

Beispiele

Das folgende Beispiel erstellt eine XmlAttributeOverrides Objekt ein XmlAttributes Objekt und ein XmlRootAttribute Objekt.The following example creates an XmlAttributeOverrides object, an XmlAttributes object, and an XmlRootAttribute object. Im Beispiel wird die XmlRootAttribute auf die XmlRoot Eigenschaft der XmlAttributes -Objekts ermöglicht und die XmlAttributes -Objekt die XmlAttributeOverrides Objekt.The example assigns the XmlRootAttribute to the XmlRoot property of the XmlAttributes object, and adds the XmlAttributes object to the XmlAttributeOverrides object. Und schließlich im Beispiel wird die XmlAttributes -Objekts durch Übergeben der Type der serialisierten Klasse, um die XmlAttributeOverrides Objekt.Lastly, the example gets the XmlAttributes object by passing the Type of the serialized class to the XmlAttributeOverrides object. In diesem Beispiel die Type ist Group.In this example, the Type is Group.

// This is the class that will be serialized.
public ref class Group
{
public:
   String^ GroupName;

   [XmlAttributeAttribute]
   int GroupCode;
};

public ref class Sample
{
public:
   XmlSerializer^ CreateOverrider()
   {
      // Create an XmlSerializer with overriding attributes.
      XmlAttributes^ attrs = gcnew XmlAttributes;
      XmlAttributeOverrides^ xOver = gcnew XmlAttributeOverrides;
      XmlRootAttribute^ xRoot = gcnew XmlRootAttribute;

      // Set a new Namespace and ElementName for the root element.
      xRoot->Namespace = "http://www.cpandl.com";
      xRoot->ElementName = "NewGroup";
      attrs->XmlRoot = xRoot;
      xOver->Add( Group::typeid, attrs );

      // Get the XmlAttributes object, based on the type.
      XmlAttributes^ tempAttrs;
      tempAttrs = xOver[ Group::typeid ];

      // Print the Namespace and ElementName of the root.
      Console::WriteLine( tempAttrs->XmlRoot->Namespace );
      Console::WriteLine( tempAttrs->XmlRoot->ElementName );
      XmlSerializer^ xSer = gcnew XmlSerializer( Group::typeid,xOver );
      return xSer;
   }
};
// 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.
   XmlAttributes attrs = new XmlAttributes();
   XmlAttributeOverrides xOver = new XmlAttributeOverrides();
   
   XmlRootAttribute xRoot = new XmlRootAttribute();
   // Set a new Namespace and ElementName for the root element.
   xRoot.Namespace = "http://www.cpandl.com";
   xRoot.ElementName = "NewGroup";
   attrs.XmlRoot = xRoot;
   
   xOver.Add(typeof(Group), attrs);

   // Get the XmlAttributes object, based on the type.
   XmlAttributes tempAttrs;
   tempAttrs = xOver[typeof(Group)];

   // Print the Namespace and ElementName of the root.
   Console.WriteLine(tempAttrs.XmlRoot.Namespace);
   Console.WriteLine(tempAttrs.XmlRoot.ElementName);

   XmlSerializer xSer = new XmlSerializer(typeof(Group), xOver);
   return xSer;
}
}
' This is the class that will be serialized.
Public Class Group
    Public GroupName As String
    <XmlAttribute()> Public GroupCode As Integer
End Class

Public Class Sample
    
    Public Function CreateOverrider() As XmlSerializer
        ' Create an XmlSerializer with overriding attributes.
        Dim attrs As New XmlAttributes()
        Dim xOver As New XmlAttributeOverrides()
        
        Dim xRoot As New XmlRootAttribute()
        ' Set a new Namespace and ElementName for the root element.
        xRoot.Namespace = "http://www.cpandl.com"
        xRoot.ElementName = "NewGroup"
        attrs.XmlRoot = xRoot
        
        xOver.Add(GetType(Group), attrs)
        
        ' Get the XmlAttributes object, based on the type.
        Dim tempAttrs As XmlAttributes
        tempAttrs = xOver(GetType(Group))
        
        ' Print the Namespace and ElementName of the root.
        Console.WriteLine(tempAttrs.XmlRoot.Namespace)
        Console.WriteLine(tempAttrs.XmlRoot.ElementName)
        
        Dim xSer As New XmlSerializer(GetType(Group), xOver)
        Return xSer
    End Function
End Class

Hinweise

Verwenden Sie diese Überladung zurückzugebenden ein XmlAttributes -Objekt, das Attribute für enthält ein XmlRootAttribute oder XmlTypeAttribute Objekt.Use this overload to return an XmlAttributes object that contains attributes for an XmlRootAttribute or XmlTypeAttribute object.

Wenn die XmlAttributes Objekt enthält Objekte, die außer Kraft setzen eine XmlArrayAttribute, XmlArrayItemAttribute, XmlElementAttribute, XmlEnumAttribute, oder XmlAttributeAttribute, Sie müssen die Überladung verwenden, der dem überschriebenen Member als auch den Typ angibt.If the XmlAttributes object contains objects that override an XmlArrayAttribute, XmlArrayItemAttribute, XmlElementAttribute, XmlEnumAttribute, or XmlAttributeAttribute, you must use the overload that specifies the overridden member as well as the type.

Siehe auch

Item[Type, String] Item[Type, String] Item[Type, String] Item[Type, String]

Ruft das dem angegebenen (Basisklassen-)Typ zugeordnete Objekt ab.Gets the object associated with the specified (base-class) type. Durch den member-Parameter wird der zu überschreibende Member der Basisklasse angegeben.The member parameter specifies the base-class member that is overridden.

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

Parameter

type
Type Type Type Type

Die Type-Basisklasse, die der Auflistung der gewünschten Attribute zugeordnet ist.The base class Type that is associated with the collection of attributes you want.

member
String String String String

Der Name des überschriebenen Member, der das zurückzugebende XmlAttributes angibt.The name of the overridden member that specifies the XmlAttributes to return.

Eigenschaftswert

Ein XmlAttributes, das die Auflistung der überschreibenden Attribute darstellt.An XmlAttributes that represents the collection of overriding attributes.

Beispiele

Das folgende Beispiel erstellt eine XmlAttributeOverrides Objekt ein XmlAttributes, und ein XmlAttributeAttribute Objekt.The following example creates an XmlAttributeOverrides object, an XmlAttributes, and an XmlAttributeAttribute object. Im Beispiel wird die XmlAttributeAttribute auf die XmlAttribute Eigenschaft der XmlAttributes -Objekt und fügt die XmlAttributes -Objekt die XmlAttributeOverrides Objekt.The example assigns the XmlAttributeAttribute to the XmlAttribute property of the XmlAttributes object and adds the XmlAttributes object to the XmlAttributeOverrides object. Und schließlich im Beispiel wird die XmlAttributes -Objekts durch Übergeben der Type von der serialisierten Klassen- und Memberebene Name, der die XmlAttributeOverrides Objekt.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 ref class Group
{
public:
   String^ GroupName;

   [XmlAttributeAttribute]
   int GroupCode;
};

public ref class Sample
{
public:
   XmlSerializer^ CreateOverrider()
   {
      // Create an XmlSerializer with overriding attributes.
      XmlAttributeOverrides^ xOver = gcnew XmlAttributeOverrides;

      /* Create an XmlAttributeAttribute object and set the 
            AttributeName property. */
      XmlAttributeAttribute^ xAtt = gcnew XmlAttributeAttribute;
      xAtt->AttributeName = "Code";

      /* Create a new XmlAttributes object and set the 
            XmlAttributeAttribute object to the XmlAttribute property. */
      XmlAttributes^ attrs = gcnew XmlAttributes;
      attrs->XmlAttribute = xAtt;

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

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

      // Create the XmlSerializer instance and return it.
      XmlSerializer^ xSer = gcnew XmlSerializer( Group::typeid,xOver );
      return xSer;
   }
};
// 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;
}
}
' This is the class that will be serialized.
Public Class Group
    Public GroupName As String
    <XmlAttribute()> Public GroupCode As Integer
End Class

Public Class Sample
    
    Public Function CreateOverrider() As XmlSerializer
        ' Create an XmlSerializer with overriding attributes.
        Dim xOver As New XmlAttributeOverrides()
        
        ' Create an XmlAttributeAttribute object and set the
        ' AttributeName property. 
        Dim xAtt As New XmlAttributeAttribute()
        xAtt.AttributeName = "Code"
        
        ' Create a new XmlAttributes object and set the
        ' XmlAttributeAttribute object to the XmlAttribute property. 
        Dim attrs As New XmlAttributes()
        attrs.XmlAttribute = xAtt
        
        ' Add the XmlAttributes to the XmlAttributeOverrides object. The
        ' name of the overridden attribute must be specified. 
        xOver.Add(GetType(Group), "GroupCode", attrs)
                
        ' Get the XmlAttributes object for the type and member.
        Dim tempAttrs As XmlAttributes
        tempAttrs = xOver(GetType(Group), "GroupCode")
        Console.WriteLine(tempAttrs.XmlAttribute.AttributeName)
        
        ' Create the XmlSerializer instance and return it.
        Dim xSer As New XmlSerializer(GetType(Group), xOver)
        Return xSer
    End Function
End Class

Hinweise

Verwenden Sie diese Überladung zurückzugebenden ein XmlAttributes Objekt, das enthält Objekte, die Überschreibung eine XmlArrayAttribute, XmlArrayItemAttribute, XmlAttributeAttribute, XmlElementAttribute, oder XmlEnumAttribute.Use this overload to return an XmlAttributes object that contains objects that override an XmlArrayAttribute, XmlArrayItemAttribute, XmlAttributeAttribute, XmlElementAttribute, or XmlEnumAttribute. Wenn die XmlAttributes Objekt enthält eine XmlRootAttribute oder XmlTypeAttribute, Sie müssen die Überladung verwenden, die nur die überschriebenen Typ angibt.If the XmlAttributes object contains an XmlRootAttribute or XmlTypeAttribute, you must use the overload that specifies only the overridden type.

Siehe auch

Gilt für: