IExtensibleDataObject Antarmuka
Definisi
Penting
Beberapa informasi terkait produk prarilis yang dapat diubah secara signifikan sebelum dirilis. Microsoft tidak memberikan jaminan, tersirat maupun tersurat, sehubungan dengan informasi yang diberikan di sini.
Menyediakan struktur data untuk menyimpan data tambahan yang XmlObjectSerializer ditemui oleh selama deserialisasi jenis yang ditandai dengan DataContractAttribute atribut .
public interface class IExtensibleDataObject
public interface IExtensibleDataObject
type IExtensibleDataObject = interface
Public Interface IExtensibleDataObject
- Turunan
Contoh
Kode berikut menunjukkan instans jenis (PersonVersion2) yang merupakan versi kedua dari jenis yang dapat diserialisasikan (Person). Versi kedua berisi data tambahan (ID bidang) yang tidak ada di versi pertama.
// 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
Keterangan
Antarmuka IExtensibleDataObject menyediakan satu properti yang mengatur atau mengembalikan struktur yang digunakan untuk menyimpan data yang berada di luar kontrak data. Data tambahan disimpan dalam instans ExtensionDataObject kelas dan diakses melalui ExtensionData properti . Dalam operasi pulang-pergi di mana data diterima, diproses, dan dikirim kembali, data tambahan dikirim kembali ke pengirim asli secara utuh. Ini berguna untuk menyimpan data yang diterima dari versi kontrak mendatang. Jika Anda tidak menerapkan antarmuka, data tambahan diabaikan dan dibuang selama operasi pulang pergi.
Untuk menggunakan fitur pengelolaan versi ini
Terapkan IExtensibleDataObject antarmuka di kelas .
Tambahkan properti ExtensionData ke jenis Anda.
Tambahkan anggota privat jenis ExtensionDataObject ke kelas .
Terapkan metode dapatkan dan atur untuk properti menggunakan anggota privat baru.
Terapkan DataContractAttribute atribut ke kelas . Atur Name properti dan Namespace ke nilai yang sesuai jika perlu.
Untuk informasi selengkapnya tentang penerapan versi jenis, lihat Penerapan Versi Kontrak Data. Untuk informasi tentang membuat kontrak data yang kompatibel ke depan, lihat Forward-Compatible Kontrak Data. Untuk informasi selengkapnya tentang kontrak data, lihat Menggunakan Kontrak Data.
Properti
| Nama | Deskripsi |
|---|---|
| ExtensionData |
Mendapatkan atau mengatur struktur yang berisi data tambahan. |