IDataContractSurrogate.GetDataContractType(Type) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
During serialization, deserialization, and schema import and export, returns a data contract type that substitutes the specified type.
public:
Type ^ GetDataContractType(Type ^ type);
public Type GetDataContractType (Type type);
abstract member GetDataContractType : Type -> Type
Public Function GetDataContractType (type As Type) As Type
Parameters
Returns
The Type to substitute for the type
value. This type must be serializable by the DataContractSerializer. For example, it must be marked with the DataContractAttribute attribute or other mechanisms that the serializer recognizes.
Examples
The following example shows an implementation of the GetDataContractType method.
public Type GetDataContractType(Type type)
{
Console.WriteLine("GetDataContractType invoked");
Console.WriteLine("\t type name: {0}", type.Name);
// "Person" will be serialized as "PersonSurrogated"
// This method is called during serialization,
// deserialization, and schema export.
if (typeof(Person).IsAssignableFrom(type))
{
Console.WriteLine("\t returning PersonSurrogated");
return typeof(PersonSurrogated);
}
return type;
}
Public Function GetDataContractType(ByVal type As Type) As Type _
Implements IDataContractSurrogate.GetDataContractType
Console.WriteLine("GetDataContractType invoked")
Console.WriteLine(vbTab & "type name: {0}", type.Name)
' "Person" will be serialized as "PersonSurrogated"
' This method is called during serialization,
' deserialization, and schema export.
If GetType(Person).IsAssignableFrom(type) Then
Console.WriteLine(vbTab & "returning PersonSurrogated")
Return GetType(PersonSurrogated)
End If
Return type
End Function
Applies to
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈