IExtensibleDataObject Interface
Definição
Fornece uma estrutura de dados para armazenar dados extra encontrados pelo XmlObjectSerializer durante a desserialização de um tipo marcado com o 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
Exemplos
O código a seguir mostra uma instância de um tipo ( PersonVersion2 ) que é a segunda versão de um tipo serializável ( Person ).The following code shows an instance of a type (PersonVersion2) that is the second version of a serializable type (Person). A segunda versão contém dados extras ( ID campo) que não estão presentes na primeira versão.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
Comentários
A IExtensibleDataObject interface fornece uma única propriedade que define ou retorna uma estrutura usada para armazenar dados externos a um contrato de dados.The IExtensibleDataObject interface provides a single property that sets or returns a structure used to store data that is external to a data contract. Os dados extras são armazenados em uma instância da ExtensionDataObject classe e acessados por meio da ExtensionData propriedade.The extra data is stored in an instance of the ExtensionDataObject class and accessed through the ExtensionData property. Em uma operação de ida e volta onde os dados são recebidos, processados e enviados de volta, os dados extras são enviados de volta ao remetente 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. Isso é útil para armazenar dados recebidos de versões futuras do contrato.This is useful to store data received from future versions of the contract. Se você não implementar a interface, todos os dados adicionais serão ignorados e descartados durante uma operação de ida e volta.If you do not implement the interface, any extra data is ignored and discarded during a roundtrip operation.
Para usar este recurso de controle de versãoTo use this versioning feature
Implemente a IExtensibleDataObject interface em uma classe.Implement the IExtensibleDataObject interface in a class.
Adicione a ExtensionData propriedade ao seu tipo.Add the ExtensionData property to your type.
Adicione um membro privado do tipo ExtensionDataObject à classe.Add a private member of type ExtensionDataObject to the class.
Implemente os métodos get e Set para a propriedade usando o novo membro privado.Implement get and set methods for the property using the new private member.
Aplique o DataContractAttribute atributo à classe.Apply the DataContractAttribute attribute to the class. Defina as Name Namespace Propriedades e para os valores apropriados, se necessário.Set the Name and Namespace properties to appropriate values if necessary.
Para obter mais informações sobre o controle de versão de tipos, consulte controle de versão de contrato de dados.For more information about versioning of types, see Data Contract Versioning. Para obter informações sobre como criar contratos de dados compatíveis com o encaminhamento, consulte contratos de dados compatíveis com o encaminhamento.For information about creating forward-compatible data contracts, see Forward-Compatible Data Contracts. Para obter mais informações sobre contratos de dados, consulte usando contratos de dados.For more information about data contracts, see Using Data Contracts.
Propriedades
| ExtensionData |
Obtém ou define a estrutura que contém dados extras.Gets or sets the structure that contains extra data. |