XmlIncludeAttribute XmlIncludeAttribute XmlIncludeAttribute XmlIncludeAttribute Class

Definición

Permite que XmlSerializer reconozca un tipo al serializar o deserializar un objeto.Allows the XmlSerializer to recognize a type when it serializes or deserializes an object.

public ref class XmlIncludeAttribute : Attribute
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Interface | System.AttributeTargets.Method | System.AttributeTargets.Struct, AllowMultiple=true)]
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Struct | System.AttributeTargets.Method, AllowMultiple=true)]
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Struct | System.AttributeTargets.Method | System.AttributeTargets.Interface, AllowMultiple=true)]
public class XmlIncludeAttribute : Attribute
type XmlIncludeAttribute = class
    inherit Attribute
Public Class XmlIncludeAttribute
Inherits Attribute
Herencia
XmlIncludeAttributeXmlIncludeAttributeXmlIncludeAttributeXmlIncludeAttribute
Atributos

Ejemplos

En el ejemplo siguiente se muestran tres clases, dos de las cuales se heredan de la tercera.The following example shows three classes, two of which inherit from the third. XmlIncludeAttribute En el ejemplo se aplica a un método que devuelve una instancia de una de las clases derivadas.The example applies the XmlIncludeAttribute to a method that returns an instance of one of the derived classes.

<%@ 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 {
}

Comentarios

Use cuando llame al XmlSerializer método Deserialize o de la clase. Serialize XmlIncludeAttributeUse the XmlIncludeAttribute when you call the Serialize or Deserialize method of the XmlSerializer class.

Al aplicar XmlIncludeAttribute, especifique el Type de la clase derivada.When applying the XmlIncludeAttribute, specify the Type of the derived class. XmlSerializer Cuando serializa objetos que incluyen la clase base y la clase derivada, puede reconocer ambos tipos de objeto.When the XmlSerializer serializes objects that include both the base and the derived class, it can then recognize both object types.

Puede usar el XmlIncludeAttribute para incluir clases derivadas en los documentos de descripción de servicio que se escriben en el lenguaje de descripción de servicios web (WSDL).You can use the XmlIncludeAttribute to include derived classes in service description documents that are written in the Web Services Description Language (WSDL). Por ejemplo, si un método devuelve Object, XmlIncludeAttribute se aplica al método y se especifican los tipos reales que se van a devolver.For example, if a method returns an Object, apply the XmlIncludeAttribute to the method and specify the actual types to return.

Para obtener más información sobre el WSDL, vea lenguaje de descripción de servicios web (WSDL) 1,1.For more information on the WSDL, see Web Services Description Language (WSDL) 1.1.

Constructores

XmlIncludeAttribute(Type) XmlIncludeAttribute(Type) XmlIncludeAttribute(Type) XmlIncludeAttribute(Type)

Inicializa una nueva instancia de la clase XmlIncludeAttribute.Initializes a new instance of the XmlIncludeAttribute class.

Propiedades

Type Type Type Type

Obtiene o establece el tipo de objeto que se va a incluir.Gets or sets the type of the object to include.

TypeId TypeId TypeId TypeId

Cuando se implementa en una clase derivada, obtiene un identificador único para este Attribute.When implemented in a derived class, gets a unique identifier for this Attribute.

(Inherited from Attribute)

Métodos

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Devuelve un valor que indica si esta instancia es igual que un objeto especificado.Returns a value that indicates whether this instance is equal to a specified object.

(Inherited from Attribute)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Devuelve el código hash de esta instancia.Returns the hash code for this instance.

(Inherited from Attribute)
GetType() GetType() GetType() GetType()

Obtiene el Type de la instancia actual.Gets the Type of the current instance.

(Inherited from Object)
IsDefaultAttribute() IsDefaultAttribute() IsDefaultAttribute() IsDefaultAttribute()

Si se reemplaza en una clase derivada, indica si el valor de esta instancia es el valor predeterminado de la clase derivada.When overridden in a derived class, indicates whether the value of this instance is the default value for the derived class.

(Inherited from Attribute)
Match(Object) Match(Object) Match(Object) Match(Object)

Cuando se invalida en una clase derivada, devuelve un valor que indica si esta instancia es igual a un objeto especificado.When overridden in a derived class, returns a value that indicates whether this instance equals a specified object.

(Inherited from Attribute)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Crea una copia superficial del objeto Object actual.Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

Devuelve una cadena que representa el objeto actual.Returns a string that represents the current object.

(Inherited from Object)

Implementaciones de interfaz explícitas

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

Asigna un conjunto de nombres a un conjunto correspondiente de identificadores de envío.Maps a set of names to a corresponding set of dispatch identifiers.

(Inherited from Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr) _Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Obtiene la información de tipos de un objeto, que puede utilizarse para obtener la información de tipos de una interfaz.Retrieves the type information for an object, which can be used to get the type information for an interface.

(Inherited from Attribute)
_Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32) _Attribute.GetTypeInfoCount(UInt32)

Recupera el número de interfaces de información de tipo que proporciona un objeto (0 ó 1).Retrieves the number of type information interfaces that an object provides (either 0 or 1).

(Inherited from Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) _Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Proporciona acceso a las propiedades y los métodos expuestos por un objeto.Provides access to properties and methods exposed by an object.

(Inherited from Attribute)

Se aplica a

Consulte también: