IExtensibleDataObject 인터페이스

정의

특성으로 표시된 XmlObjectSerializer 형식을 역직렬화하는 동안 발생하는 DataContractAttribute 추가 데이터를 저장하는 데이터 구조를 제공합니다.

public interface class IExtensibleDataObject
public interface IExtensibleDataObject
type IExtensibleDataObject = interface
Public Interface IExtensibleDataObject
파생

예제

다음 코드는 직렬화 가능한 형식(PersonVersion2)의 두 번째 버전인 형식(Person)의 인스턴스를 보여 줍니다. 두 번째 버전에는 첫 번째 버전에 없는 추가 데이터(ID 필드)가 포함됩니다.

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

설명

인터페이스는 IExtensibleDataObject 데이터 계약 외부에 있는 데이터를 저장하는 데 사용되는 구조를 설정하거나 반환하는 단일 속성을 제공합니다. 추가 데이터는 클래스의 ExtensionDataObject 인스턴스에 저장되고 속성을 통해 ExtensionData 액세스됩니다. 데이터가 수신, 처리 및 다시 전송되는 왕복 작업에서 추가 데이터는 원래 보낸 사람에게 그대로 다시 전송됩니다. 이는 이후 버전의 계약에서 받은 데이터를 저장하는 데 유용합니다. 인터페이스를 구현하지 않으면 왕복 작업 중에 추가 데이터가 무시되고 삭제됩니다.

이 버전 관리 기능을 사용하려면

  1. 클래스에서 IExtensibleDataObject 인터페이스를 구현합니다.

  2. 형식에 ExtensionData 속성을 추가합니다.

  3. 클래스에 형식 ExtensionDataObject 의 프라이빗 멤버를 추가합니다.

  4. 새 프라이빗 멤버를 사용하여 속성에 대한 get 및 set 메서드를 구현합니다.

  5. 클래스에 DataContractAttribute 특성을 적용합니다. NameNamespace 속성을 필요한 경우 적절한 값으로 설정합니다.

형식의 버전 관리에 대한 자세한 내용은 데이터 계약 버전 관리를 참조하세요. 정방향 호환 데이터 계약을 만드는 방법에 대한 자세한 내용은 Forward-Compatible 데이터 계약을 참조하세요. 데이터 계약에 대한 자세한 내용은 데이터 계약 사용을 참조하세요.

속성

Name Description
ExtensionData

추가 데이터가 포함된 구조를 가져오거나 설정합니다.

적용 대상

추가 정보