XmlElementAttributes Třída

Definice

Představuje kolekci XmlElementAttribute objektů, které XmlSerializer používají k přepsání výchozího způsobu serializace třídy.

public ref class XmlElementAttributes : System::Collections::IList
public ref class XmlElementAttributes : System::Collections::CollectionBase
public class XmlElementAttributes : System.Collections.IList
public class XmlElementAttributes : System.Collections.CollectionBase
type XmlElementAttributes = class
    interface ICollection
    interface IEnumerable
    interface IList
type XmlElementAttributes = class
    inherit CollectionBase
Public Class XmlElementAttributes
Implements IList
Public Class XmlElementAttributes
Inherits CollectionBase
Dědičnost
XmlElementAttributes
Dědičnost
XmlElementAttributes
Implementuje

Příklady

Následující příklad serializuje Transportation třídu, která obsahuje jedno pole s názvem Vehicles , které vrací ArrayList. Příklad nejprve použije dvě instance XmlElementAttribute třídy na Vehicles pole, které určuje typy objektů XmlSerializer , které vloží do pole. Příklad pak vytvoří dva XmlElementAttribute objekty k přepsání chování atributů použitých na Vehicles vlastnost. Dva přepsání objekty jsou přidány do XmlElementAttributes kolekce objektu XmlAttributes. Nakonec příklad přidá do objektu XmlAttributes XmlAttributeOverrides, který umožňuje XmlSerializer vložit nové typy objektů do ArrayList vrácené polem Vehicles .

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

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

public ref class Car
{
public:
   String^ Name;
};

public ref class Plane
{
public:
   String^ Name;
};

public ref class Truck
{
public:
   String^ Name;
};

public ref class Train
{
public:
   String^ Name;
};

public ref class Transportation
{
public:

   // Override these two XmlElementAttributes.

   [XmlElement(Car::typeid),
   XmlElement(Plane::typeid)]
   ArrayList^ Vehicles;
};

XmlSerializer^ CreateOverrider()
{
   // Create XmlAtrributes and XmlAttributeOverrides instances. 
   XmlAttributes^ attrs = gcnew XmlAttributes;
   XmlAttributeOverrides^ xOver = gcnew XmlAttributeOverrides;

   /* Create an XmlElementAttributes object to override 
      one of the attributes applied to the Vehicles property. */
   XmlElementAttribute^ xElement1 = gcnew XmlElementAttribute( Truck::typeid );

   // Add the XmlElementAttribute to the collection.
   attrs->XmlElements->Add( xElement1 );

   /* Create a second XmlElementAttribute and 
      add it to the collection. */
   XmlElementAttribute^ xElement2 = gcnew XmlElementAttribute( Train::typeid );
   attrs->XmlElements->Add( xElement2 );

   /* Add the XmlAttributes to the XmlAttributeOverrides,
      specifying the member to override. */
   xOver->Add( Transportation::typeid, "Vehicles", attrs );

   // Create the XmlSerializer, and return it.
   XmlSerializer^ xSer = gcnew XmlSerializer( Transportation::typeid,xOver );
   return xSer;
}

void SerializeObject( String^ filename )
{
   // Create an XmlSerializer instance.
   XmlSerializer^ xSer = CreateOverrider();

   // Create the object.
   Transportation^ myTransportation = gcnew Transportation;

   /* Create two new, overriding objects that can be
      inserted into the Vehicles array. */
   myTransportation->Vehicles = gcnew ArrayList;
   Truck^ myTruck = gcnew Truck;
   myTruck->Name = "MyTruck";
   Train^ myTrain = gcnew Train;
   myTrain->Name = "MyTrain";
   myTransportation->Vehicles->Add( myTruck );
   myTransportation->Vehicles->Add( myTrain );
   TextWriter^ writer = gcnew StreamWriter( filename );
   xSer->Serialize( writer, myTransportation );
}

int main()
{
   SerializeObject( "OverrideElement.xml" );
}
using System;
using System.IO;
using System.Xml.Serialization;
using System.Collections;
using System.Xml;

public class Transportation
{
   // Override these two XmlElementAttributes.
   [XmlElement(typeof(Car)),
   XmlElement(typeof(Plane))]
   public ArrayList Vehicles;
}

public class Car
{
   public string Name;
}

public class Plane
{
   public string Name;
}

public class Truck
{
   public string Name;
}

public class Train
{
   public string Name;
}

public class Test
{
   public static void Main()
   {
      Test t = new Test();
      t.SerializeObject("OverrideElement.xml");
   }

   public XmlSerializer CreateOverrider()
   {
      // Create XmlAtrributes and XmlAttributeOverrides instances.

      XmlAttributes attrs = new XmlAttributes();

      XmlAttributeOverrides xOver =
      new XmlAttributeOverrides();

      /* Create an XmlElementAttributes object to override
      one of the attributes applied to the Vehicles property. */
      XmlElementAttribute xElement1 =
      new XmlElementAttribute(typeof(Truck));
      // Add the XmlElementAttribute to the collection.
      attrs.XmlElements.Add(xElement1);

      /* Create a second XmlElementAttribute and
      add it to the collection. */
      XmlElementAttribute xElement2 =
      new XmlElementAttribute(typeof(Train));
      attrs.XmlElements.Add(xElement2);

      /* Add the XmlAttributes to the XmlAttributeOverrides,
      specifying the member to override. */
      xOver.Add(typeof(Transportation), "Vehicles", attrs);

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

   public void SerializeObject(string filename)
   {
      // Create an XmlSerializer instance.
      XmlSerializer xSer = CreateOverrider();

      // Create the object.
      Transportation myTransportation =
      new Transportation();

      /* Create two new, overriding objects that can be
      inserted into the Vehicles array. */
      myTransportation.Vehicles = new ArrayList();
      Truck myTruck = new Truck();
      myTruck.Name = "MyTruck";

      Train myTrain = new Train();
      myTrain.Name = "MyTrain";

      myTransportation.Vehicles.Add(myTruck);
      myTransportation.Vehicles.Add(myTrain);

      TextWriter writer = new StreamWriter(filename);
      xSer.Serialize(writer, myTransportation);
   }
}
Imports System.IO
Imports System.Xml.Serialization
Imports System.Collections
Imports System.Xml


Public Class Transportation
    ' Override these two XmlElementAttributes.
    <XmlElement(GetType(Car)), _
     XmlElement(GetType(Plane))> _
    Public Vehicles As ArrayList
End Class

Public Class Car
    Public Name As String
End Class

Public Class Plane
    Public Name As String
End Class

Public Class Truck
    Public Name As String
End Class

Public Class Train
    Public Name As String
End Class

Public Class Test
    
    Public Shared Sub Main()
        Dim t As New Test()
        t.SerializeObject("OverrideElement.xml")
    End Sub
    
    
    Public Function CreateOverrider() As XmlSerializer
        ' Create XmlAtrributes and XmlAttributeOverrides instances. 
        Dim attrs As New XmlAttributes()
        
        Dim xOver As New XmlAttributeOverrides()
        
        ' Create an XmlElementAttributes object to override
        ' one of the attributes applied to the Vehicles property. 
        Dim xElement1 As New XmlElementAttribute(GetType(Truck))
        ' Add the XmlElementAttribute to the collection.
        attrs.XmlElements.Add(xElement1)
        
        ' Create a second XmlElementAttribute and
        ' add it to the collection. 
        Dim xElement2 As New XmlElementAttribute(GetType(Train))
        attrs.XmlElements.Add(xElement2)
        
        ' Add the XmlAttributes to the XmlAttributeOverrides,
        ' specifying the member to override. 
        xOver.Add(GetType(Transportation), "Vehicles", attrs)
        
        ' Create the XmlSerializer, and return it.
        Dim xSer As New XmlSerializer(GetType(Transportation), xOver)
        Return xSer
    End Function
    
    
    Public Sub SerializeObject(ByVal filename As String)
        ' Create an XmlSerializer instance.
        Dim xSer As XmlSerializer = CreateOverrider()
        
        ' Create the object.
        Dim myTransportation As New Transportation()
        
        ' Create two new, overriding objects that can be
        ' inserted into the Vehicles array. 
        myTransportation.Vehicles = New ArrayList()
        Dim myTruck As New Truck()
        myTruck.Name = "MyTruck"
        
        Dim myTrain As New Train()
        myTrain.Name = "MyTrain"
        
        myTransportation.Vehicles.Add(myTruck)
        myTransportation.Vehicles.Add(myTrain)
        
        Dim writer As New StreamWriter(filename)
        xSer.Serialize(writer, myTransportation)
    End Sub
End Class

Poznámky

Vrátí vlastnost XmlElementAttributes XmlElements XmlAttributes třídy. XmlAttributeOverrides Pomocí třídy a XmlAttributes třídy můžete přepsat výchozí způsob XmlSerializer serializace třídy.

Konstruktory

XmlElementAttributes()

Inicializuje novou instanci XmlElementAttributes třídy.

Vlastnosti

Capacity

Získá nebo nastaví počet prvků, které CollectionBase může obsahovat.

(Zděděno od CollectionBase)
Count

Získá počet elementů obsažených v objektu ICollection.

Count

Získá počet prvků obsažených v CollectionBase instanci. Tuto vlastnost nelze přepsat.

(Zděděno od CollectionBase)
InnerList

ArrayList Získá obsahující seznam prvků v CollectionBase instanci.

(Zděděno od CollectionBase)
Item[Int32]

Získá nebo nastaví prvek u zadaného indexu.

List

IList Získá obsahující seznam prvků v CollectionBase instanci.

(Zděděno od CollectionBase)

Metody

Add(XmlElementAttribute)

Přidá do kolekce.XmlElementAttribute

Clear()

Odebere všechny položky z objektu IList.

Clear()

Odebere všechny objekty z CollectionBase instance. Tuto metodu nelze přepsat.

(Zděděno od CollectionBase)
Contains(XmlElementAttribute)

Určuje, zda kolekce obsahuje zadaný objekt.

CopyTo(XmlElementAttribute[], Int32)

Zkopíruje XmlElementAttributesho nebo jeho část do jednorozměrného pole.

Equals(Object)

Určí, zda se zadaný objekt rovná aktuálnímu objektu.

(Zděděno od Object)
GetEnumerator()

Vrací enumerátor procházející kolekci.

GetEnumerator()

Vrátí výčet, který iteruje prostřednictvím CollectionBase instance.

(Zděděno od CollectionBase)
GetHashCode()

Slouží jako výchozí funkce hash.

(Zděděno od Object)
GetType()

Type Získá aktuální instanci.

(Zděděno od Object)
IndexOf(XmlElementAttribute)

Získá index zadaného XmlElementAttribute.

Insert(Int32, XmlElementAttribute)

Vloží do kolekce.XmlElementAttribute

MemberwiseClone()

Vytvoří použádnou kopii aktuálního souboru Object.

(Zděděno od Object)
OnClear()

Provádí další vlastní procesy při vymazání obsahu CollectionBase instance.

(Zděděno od CollectionBase)
OnClearComplete()

Provede další vlastní procesy po vymazání obsahu CollectionBase instance.

(Zděděno od CollectionBase)
OnInsert(Int32, Object)

Před vložením nového prvku do CollectionBase instance provede další vlastní procesy.

(Zděděno od CollectionBase)
OnInsertComplete(Int32, Object)

Provede další vlastní procesy po vložení nového prvku do CollectionBase instance.

(Zděděno od CollectionBase)
OnRemove(Int32, Object)

Provádí další vlastní procesy při odebírání elementu CollectionBase z instance.

(Zděděno od CollectionBase)
OnRemoveComplete(Int32, Object)

Provede další vlastní procesy po odebrání elementu CollectionBase z instance.

(Zděděno od CollectionBase)
OnSet(Int32, Object, Object)

Provede další vlastní procesy před nastavením hodnoty v CollectionBase instanci.

(Zděděno od CollectionBase)
OnSetComplete(Int32, Object, Object)

Provede další vlastní procesy po nastavení hodnoty v CollectionBase instanci.

(Zděděno od CollectionBase)
OnValidate(Object)

Provádí další vlastní procesy při ověřování hodnoty.

(Zděděno od CollectionBase)
Remove(XmlElementAttribute)

Odebere zadaný objekt z kolekce.

RemoveAt(Int32)

Odebere IList položku v zadaném indexu.

RemoveAt(Int32)

Odebere prvek v zadaném indexu CollectionBase instance. Tato metoda není přepsána.

(Zděděno od CollectionBase)
ToString()

Vrátí řetězec, který představuje aktuální objekt.

(Zděděno od Object)

Explicitní implementace rozhraní

ICollection.CopyTo(Array, Int32)

Zkopíruje prvky do objektu ICollection Array, počínaje konkrétním Array indexem.

ICollection.CopyTo(Array, Int32)

Zkopíruje celý CollectionBase objekt do kompatibilního jednorozměrného Array, počínaje zadaným indexem cílového pole.

(Zděděno od CollectionBase)
ICollection.IsSynchronized

Získá hodnotu označující, zda je přístup k této ICollection synchronizaci (bezpečné vlákno).

ICollection.IsSynchronized

Získá hodnotu označující, zda je přístup k ho CollectionBase synchronizován (bezpečné vlákno).

(Zděděno od CollectionBase)
ICollection.SyncRoot

Získá objekt, který lze použít k synchronizaci přístupu k .ICollection

ICollection.SyncRoot

Získá objekt, který lze použít k synchronizaci přístupu k CollectionBase.

(Zděděno od CollectionBase)
IList.Add(Object)

Přidá položku do objektu IList.

IList.Add(Object)

Přidá objekt na konec objektu CollectionBase.

(Zděděno od CollectionBase)
IList.Contains(Object)

Určuje, zda IList obsahuje konkrétní hodnotu.

IList.Contains(Object)

Určuje, zda CollectionBase obsahuje konkrétní prvek.

(Zděděno od CollectionBase)
IList.IndexOf(Object)

Určuje index konkrétní položky v sadě IList.

IList.IndexOf(Object)

Vyhledá zadaný Object index a vrátí nulový index prvního výskytu v rámci celého CollectionBasesouboru .

(Zděděno od CollectionBase)
IList.Insert(Int32, Object)

Vloží položku do zadaného indexu IList .

IList.Insert(Int32, Object)

Vloží prvek do zadaného indexu CollectionBase .

(Zděděno od CollectionBase)
IList.IsFixedSize

Získá hodnotu určující, zda IList má pevnou velikost.

IList.IsFixedSize

Získá hodnotu určující, zda CollectionBase má pevnou velikost.

(Zděděno od CollectionBase)
IList.IsReadOnly

Získá hodnotu, která určuje, zda je IList určena jen pro čtení.

IList.IsReadOnly

Získá hodnotu, která určuje, zda je CollectionBase určena jen pro čtení.

(Zděděno od CollectionBase)
IList.Item[Int32]

Získá nebo nastaví prvek u zadaného indexu.

IList.Item[Int32]

Získá nebo nastaví prvek u zadaného indexu.

(Zděděno od CollectionBase)
IList.Remove(Object)

Odebere první výskyt konkrétního objektu z objektu IList.

IList.Remove(Object)

Odebere první výskyt konkrétního objektu z objektu CollectionBase.

(Zděděno od CollectionBase)

Metody rozšíření

Cast<TResult>(IEnumerable)

Přetypuje prvky zadaného IEnumerable typu.

OfType<TResult>(IEnumerable)

Filtruje prvky IEnumerable založené na zadaném typu.

AsParallel(IEnumerable)

Umožňuje paralelizaci dotazu.

AsQueryable(IEnumerable)

Převede na IEnumerable IQueryable.

Platí pro

Viz také