IExtensibleDataObject Interfaz

Definición

Proporciona una estructura de datos para almacenar datos adicionales detectados por XmlObjectSerializer durante la deserialización de un tipo marcada con el atributo DataContractAttribute.Provides a data structure to store extra data encountered by the XmlObjectSerializer during deserialization of a type marked with the DataContractAttribute attribute.

public interface class IExtensibleDataObject
public interface IExtensibleDataObject
type IExtensibleDataObject = interface
Public Interface IExtensibleDataObject
Derivado

Ejemplos

El código siguiente muestra una instancia de un tipo (PersonVersion2) que es la segunda versión de un tipo serializable (Person).The following code shows an instance of a type (PersonVersion2) that is the second version of a serializable type (Person). La segunda versión contiene datos adicionales (campo ID) que no se encuentran en la primera versión.The second version contains extra data (ID field) that is not present in the first version.

// Implement the IExtensibleDataObject interface 
// to store the extra data for future versions.
[DataContract(
    Name = "Person",
    Namespace = "http://www.cohowinery.com/employees")]
class Person : IExtensibleDataObject
{
    // To implement the IExtensibleDataObject interface,
    // you must implement the ExtensionData property. The property
    // holds data from future versions of the class for backward
    // compatibility.
    private ExtensionDataObject extensionDataObject_value;
    public ExtensionDataObject ExtensionData
    {
        get
        {
            return extensionDataObject_value;
        }
        set
        {
            extensionDataObject_value = value;
        }
    }
    [DataMember]
    public string Name;
}

// The second version of the class adds a new field. The field's 
// data is stored in the ExtensionDataObject field of
// the first version (Person). You must also set the Name property 
// of the DataContractAttribute to match the first version. 
// If necessary, also set the Namespace property so that the 
// name of the contracts is the same.
[DataContract(Name = "Person",
    Namespace = "http://www.cohowinery.com/employees")]
class PersonVersion2 : IExtensibleDataObject
{
    // Best practice: add an Order number to new members.
    [DataMember(Order=2)]
    public int ID;

    [DataMember]
    public string Name;

    private ExtensionDataObject extensionDataObject_value;
    public ExtensionDataObject ExtensionData
    {
        get
        {
            return extensionDataObject_value;
        }
        set
        {
            extensionDataObject_value = value;
        }
    }
}
' Implement the IExtensibleDataObject interface 
' to store the extra data for future versions.
<DataContract(Name := "Person", [Namespace] := "http://www.cohowinery.com/employees")>  _
Class Person
    Implements IExtensibleDataObject
    ' To implement the IExtensibleDataObject interface,
    ' you must implement the ExtensionData property. The property
    ' holds data from future versions of the class for backward
    ' compatibility.
    Private extensionDataObject_value As ExtensionDataObject
    
    Public Property ExtensionData() As ExtensionDataObject _
       Implements IExtensibleDataObject.ExtensionData
        Get
            Return extensionDataObject_value
        End Get
        Set
            extensionDataObject_value = value
        End Set
    End Property
    <DataMember()>  _
    Public Name As String
End Class 

' The second version of the class adds a new field. The field's 
' data is stored in the ExtensionDataObject field of
' the first version (Person). You must also set the Name property 
' of the DataContractAttribute to match the first version. 
' If necessary, also set the Namespace property so that the 
' name of the contracts is the same.

<DataContract(Name := "Person", [Namespace] := "http://www.cohowinery.com/employees")>  _
Class PersonVersion2
    Implements IExtensibleDataObject

    ' Best practice: add an Order number to new members.
    <DataMember(Order:=2)>  _
    Public ID As Integer
    
    <DataMember()>  _
    Public Name As String
    
    Private extensionDataObject_value As ExtensionDataObject
    
    Public Property ExtensionData() As ExtensionDataObject _
       Implements IExtensibleDataObject.ExtensionData
        Get
            Return extensionDataObject_value
        End Get
        Set
            extensionDataObject_value = value
        End Set
    End Property
End Class 

Comentarios

La interfaz IExtensibleDataObject proporciona una propiedad única que establece o devuelve una estructura usada para almacenar datos externos a un contrato de datos.The IExtensibleDataObject interface provides a single property that sets or returns a structure used to store data that is external to a data contract. Los datos adicionales están almacenados en una instancia de la clase ExtensionDataObject y se obtienen acceso a ellos a través de la propiedad ExtensionData.The extra data is stored in an instance of the ExtensionDataObject class and accessed through the ExtensionData property. En una operación de ida y vuelta (round trip) donde se reciben, procesan y devuelven datos, los datos adicionales se devuelven al remitente original intactos.In a roundtrip operation where data is received, processed, and sent back, the extra data is sent back to the original sender intact. Esto es útil para almacenar datos recibidos de versiones futuras del contrato.This is useful to store data received from future versions of the contract. Si no implementa la interfaz, cualquier dato adicional se omite y descarta durante una operación de ida y vuelta (round trip).If you do not implement the interface, any extra data is ignored and discarded during a roundtrip operation.

Para usar esta característica de control de versionesTo use this versioning feature

  1. Implemente la interfaz IExtensibleDataObject en una clase.Implement the IExtensibleDataObject interface in a class.

  2. Agregue la propiedad ExtensionData a su tipo.Add the ExtensionData property to your type.

  3. Agregue un miembro privado del tipo ExtensionDataObject a la clase.Add a private member of type ExtensionDataObject to the class.

  4. Implemente los métodos get y set para la propiedad con el nuevo miembro privado.Implement get and set methods for the property using the new private member.

  5. Aplique el atributo DataContractAttribute a la clase.Apply the DataContractAttribute attribute to the class. Establezca Name y las propiedades Namespace en los valores adecuados si es necesario.Set the Name and Namespace properties to appropriate values if necessary.

Para obtener más información sobre el control de versiones de tipos, vea control de versiones de contratos de datos.For more information about versioning of types, see Data Contract Versioning. Para obtener información sobre cómo crear contratos de datos compatibles con el avance, consulte contratos de datos compatibles con el reenvío.For information about creating forward-compatible data contracts, see Forward-Compatible Data Contracts. Para obtener más información sobre los contratos de datos, consulte uso de contratos de datos.For more information about data contracts, see Using Data Contracts.

Propiedades

ExtensionData

Obtiene o establece la estructura que contiene datos adicionales.Gets or sets the structure that contains extra data.

Se aplica a

Consulte también: