IExtensibleDataObject Interfaccia
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Fornisce una struttura di dati per archiviare dati aggiuntivi rilevati da durante la XmlObjectSerializer deserializzazione di un tipo contrassegnato con l'attributo DataContractAttribute .
public interface class IExtensibleDataObject
public interface IExtensibleDataObject
type IExtensibleDataObject = interface
Public Interface IExtensibleDataObject
- Derivato
Esempio
Il codice seguente mostra un'istanza di un tipo (PersonVersion2) che rappresenta la seconda versione di un tipo serializzabile (Person). La seconda versione contiene dati aggiuntivi (ID campo) non presenti nella prima versione.
// 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
Commenti
L'interfaccia IExtensibleDataObject fornisce una singola proprietà che imposta o restituisce una struttura utilizzata per archiviare dati esterni a un contratto dati. I dati aggiuntivi vengono archiviati in un'istanza della ExtensionDataObject classe e accessibili tramite la ExtensionData proprietà . In un'operazione di round trip in cui i dati vengono ricevuti, elaborati e inviati di nuovo, i dati aggiuntivi vengono inviati al mittente originale intatti. Ciò è utile per archiviare i dati ricevuti da versioni future del contratto. Se non si implementa l'interfaccia, eventuali dati aggiuntivi vengono ignorati e rimossi durante un'operazione di round trip.
Per usare questa funzionalità di controllo delle versioni
Implementare l'interfaccia IExtensibleDataObject in una classe .
Aggiungi la ExtensionData proprietà al tuo tipo.
Aggiungere un membro privato di tipo ExtensionDataObject alla classe .
Implementare i metodi di accesso get e set per la proprietà usando il nuovo membro privato.
Applicare l'attributo DataContractAttribute alla classe . Impostare le Name proprietà e Namespace sui valori appropriati, se necessario.
Per ulteriori informazioni sul versionamento dei tipi, vedere Versionamento del contratto dati. Per informazioni sulla creazione di contratti dati compatibili con le versioni successive, vedere Forward-Compatible Contratti dati. Per altre informazioni sui contratti dati, vedere Uso di contratti dati.
Proprietà
| Nome | Descrizione |
|---|---|
| ExtensionData |
Ottiene o imposta la struttura che contiene dati aggiuntivi. |