Sdílet prostřednictvím


XmlArrayItemAttribute.ElementName Vlastnost

Definice

Získá nebo nastaví název vygenerovaného XML elementu.

public:
 property System::String ^ ElementName { System::String ^ get(); void set(System::String ^ value); };
public string ElementName { get; set; }
member this.ElementName : string with get, set
Public Property ElementName As String

Hodnota vlastnosti

Název vygenerovaného elementu XML. Výchozí hodnota je identifikátor člena.

Příklady

Následující příklad nastaví ElementName vlastnost pro Vehicle a Car class - tím změnit názvy xml elementů, které generuje XmlSerializer pro tyto třídy.

public class Transportation
{
   [XmlArray("Vehicles")]
   /* Specifies acceptable types and the ElementName generated
      for each object type. */
   [XmlArrayItem(typeof(Vehicle), ElementName = "Transport"),
   XmlArrayItem(typeof(Car), ElementName = "Automobile")]
   public Vehicle[] MyVehicles;
}

// By default, this class results in XML elements named "Vehicle".
public class Vehicle
{
   public string id;
}

// By default, this class results in XML elements named "Car".
public class Car:Vehicle
{
   public string Maker;
}
Public Class Transportation
    ' Specifies acceptable types and the ElementName generated
    '  for each object type. 
    <XmlArray("Vehicles"), _
     XmlArrayItem(GetType(Vehicle), ElementName := "Transport"), _
     XmlArrayItem(GetType(Car), ElementName := "Automobile")> _
    Public MyVehicles() As Vehicle
End Class

' By default, this class results in XML elements named "Vehicle". 
Public Class Vehicle
    Public id As String
End Class

' By default, this class results in XMl elements named "Car". 
Public Class Car
    Inherits Vehicle
    Public Maker As String
End Class

Poznámky

ElementName Zadejte, zda se má název vygenerovaného elementu XML lišit od identifikátoru člena.

Stejnou ElementName hodnotu můžete nastavit na více než jeden člen třídy, pokud vygenerovaný dokument XML používá obory názvů XML k rozlišení mezi identicky pojmenovanými členy. Podrobnosti o tom, jak používat obory názvů a názvy s předponami v dokumentu XML, najdete v XmlSerializerNamespaces této třídě.

Platí pro