IExtensibleDataObject 接口
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
提供一个数据结构,用于存储 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
注解
有关此 API 的详细信息,请参阅 IExtensibleDataObject 的补充 API 备注。
属性
ExtensionData |
获取或设置包含额外数据的结构。 |