IExtensibleDataObject Arabirim

Tanım

özniteliğiyle XmlObjectSerializer işaretlenmiş bir türün seri durumdan DataContractAttribute çıkarılması sırasında tarafından karşılaşılan ek verileri depolamak için bir veri yapısı sağlar.

public interface class IExtensibleDataObject
public interface IExtensibleDataObject
type IExtensibleDataObject = interface
Public Interface IExtensibleDataObject
Türetilmiş

Örnekler

Aşağıdaki kod, serileştirilebilir türün (PersonVersion2) ikinci sürümü olan bir türün (Person) örneğini gösterir. İkinci sürüm, ilk sürümde bulunmayan ek veriler (ID alan) içerir.

// 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

Açıklamalar

Arabirim, IExtensibleDataObject bir veri sözleşmesinin dışındaki verileri depolamak için kullanılan bir yapıyı ayarlayan veya döndüren tek bir özellik sağlar. Ek veri, ExtensionDataObject sınıfının bir örneğinde depolanır ve ExtensionData özelliği üzerinden erişilir. Verilerin alındığı, işlendiği ve geri gönderildiği gidiş dönüş işleminde, ek veriler özgün gönderene olduğu gibi geri gönderilir. Bu, sözleşmenin gelecek sürümlerinden alınan verileri depolamak için yararlıdır. Arabirimi uygulamazsanız, bir gidiş dönüş işlemi sırasında ek veriler yoksayılır ve atılır.

Bu sürüm oluşturma özelliğini kullanmak için

  1. IExtensibleDataObject Arabirimini bir sınıfta uygulayın.

  2. ExtensionData özelliğini türünüze ekleyin.

  3. sınıfına türünün ExtensionDataObject özel bir üyesini ekleyin.

  4. Yeni özel üyeyi kullanarak özelliğe get ve set yöntemlerinin uygulanması.

  5. özniteliğini DataContractAttribute sınıfına uygulayın. Name gerekirse ve Namespace özelliklerini uygun değerlere ayarlayın.

Türlerin sürüm oluşturması hakkında daha fazla bilgi için bkz. Veri Sözleşmesi Sürüm Oluşturma. İleriye dönük uyumlu veri sözleşmeleri oluşturma hakkında bilgi için bkz. veri sözleşmeleriniForward-Compatible. Veri sözleşmeleri hakkında daha fazla bilgi için bkz. Veri Sözleşmelerini Kullanma.

Özellikler

Name Description
ExtensionData

Ek veri içeren yapıyı alır veya ayarlar.

Şunlara uygulanır

Ayrıca bkz.