XmlIncludeAttribute Klasa

Definicja

XmlSerializer Umożliwia rozpoznawanie typu podczas serializacji lub deserializowania obiektu.

public ref class XmlIncludeAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Interface | System.AttributeTargets.Method | System.AttributeTargets.Struct, AllowMultiple=true)]
public class XmlIncludeAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Method | System.AttributeTargets.Struct, AllowMultiple=true)]
public class XmlIncludeAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Interface | System.AttributeTargets.Method | System.AttributeTargets.Struct, AllowMultiple=true)>]
type XmlIncludeAttribute = class
    inherit Attribute
[<System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Method | System.AttributeTargets.Struct, AllowMultiple=true)>]
type XmlIncludeAttribute = class
    inherit Attribute
Public Class XmlIncludeAttribute
Inherits Attribute
Dziedziczenie
XmlIncludeAttribute
Atrybuty

Przykłady

W poniższym przykładzie przedstawiono trzy klasy, z których dwie dziedziczą po trzeciej. Przykład dotyczy XmlIncludeAttribute metody, która zwraca wystąpienie jednej z klas pochodnych.

<%@ WebService Language="C#" Class="Test" %>
 
using System;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Web.Services.Description;
using System.Xml;
using System.Xml.Schema;
using System.Xml.Serialization;
using System.Data;
 
public class Test : WebService {
   [WebMethod()]
   [return:XmlElement("MyTime", DataType="time")]
   public DateTime EchoString([XmlElement(DataType="string")] 
   string strval) {
        return DateTime.Now;
   }
 
   [WebMethod()]
   [XmlInclude(typeof(Car)), XmlInclude(typeof(Bike))]
   public Vehicle Vehicle(string licenseNumber) {
      if (licenseNumber == "0") {
         Vehicle v = new Car();
         v.licenseNumber = licenseNumber;
         return v;
      }
      else if (licenseNumber == "1") {
          Vehicle v = new Bike();
          v.licenseNumber = licenseNumber;
          return v;
      }
      else {
         return null;
      }
   }
}
[XmlRoot("NewVehicle")] 
public abstract class Vehicle {
    public string licenseNumber;
    public DateTime make;
}
 
public class Car : Vehicle {
}
 
public class Bike : Vehicle {
}

Uwagi

Użyj metody XmlIncludeAttribute podczas wywoływania Serialize metody XmlSerializer lub Deserialize klasy .

Podczas stosowania klasy XmlIncludeAttributenależy określić Type klasę pochodną. XmlSerializer Gdy serializuje obiekty, które zawierają zarówno klasę bazową, jak i pochodną, może rozpoznać oba typy obiektów.

Klasy pochodne można uwzględnić XmlIncludeAttribute w dokumentach opisu usług napisanych w języku WSDL (Web Services Description Language). Jeśli na przykład metoda zwraca wartość , zastosuj XmlIncludeAttribute metodę Objectdo metody i określ rzeczywiste typy, które mają być zwracane.

Aby uzyskać więcej informacji na temat języka WSDL, zobacz Web Services Description Language (WSDL) 1.1.

Konstruktory

XmlIncludeAttribute(Type)

Inicjuje nowe wystąpienie klasy XmlIncludeAttribute.

Właściwości

Type

Pobiera lub ustawia typ obiektu do uwzględnienia.

TypeId

Po zaimplementowaniu w klasie pochodnej pobiera unikatowy identyfikator dla tego Attributeelementu .

(Odziedziczone po Attribute)

Metody

Equals(Object)

Zwraca wartość wskazującą, czy to wystąpienie jest równe podanemu obiektowi.

(Odziedziczone po Attribute)
GetHashCode()

Zwraca wartość skrótu dla tego wystąpienia.

(Odziedziczone po Attribute)
GetType()

Type Pobiera wartość bieżącego wystąpienia.

(Odziedziczone po Object)
IsDefaultAttribute()

W przypadku zastąpienia w klasie pochodnej wskazuje, czy wartość tego wystąpienia jest wartością domyślną klasy pochodnej.

(Odziedziczone po Attribute)
Match(Object)

Po przesłonięciu w klasie pochodnej zwraca wartość wskazującą, czy to wystąpienie jest równe określonemu obiektowi.

(Odziedziczone po Attribute)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Jawne implementacje interfejsu

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

Zestaw nazw jest mapowany na odpowiedni zestaw identyfikatorów wysyłania.

(Odziedziczone po Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Pobiera informacje o typie dla obiektu, który może służyć do pobierania informacji o typie dla interfejsu.

(Odziedziczone po Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Pobiera informację o liczbie typów interfejsów, jakie zawiera obiekt (0 lub 1).

(Odziedziczone po Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Umożliwia dostęp do właściwości i metod udostępnianych przez obiekt.

(Odziedziczone po Attribute)

Dotyczy

Zobacz też