ValueSerializer 类

定义

定义从对象表示形式进行序列化过程中的转换行为的抽象类。Abstract class that defines conversion behavior for serialization from an object representation.

public ref class ValueSerializer abstract
public abstract class ValueSerializer
type ValueSerializer = class
Public MustInherit Class ValueSerializer
继承
ValueSerializer
派生

注解

转换器为序列化返回的字符串必须不太大, 并且转换器必须始终为特定值返回相同字符串。The string a converter returns for serialization must be loss-less and the converter must always return the same string for a particular value. 如果类型转换器 (派生自TypeConverter) 在其ConvertTo字符串输出实现中不满足这些要求, 则必须声明自ValueSerializer定义。If a type converter (derived from TypeConverter) does not meet these requirements in its ConvertTo implementations for string output, a custom ValueSerializer must be declared. 要么应满足要求, 要么应将 null ValueSerializer与类型相关联。 ValueSerializerEither the ValueSerializer should meet the requirements, or a null ValueSerializer should be associated with the type. ValueSerializer 通过ValueSerializerAttribute应用特性与类型相关联。A ValueSerializer is associated with a type by applying the ValueSerializerAttribute attribute.

如果为ValueSerializer null, 则表示应忽略对象图中的转换到字符串转换的类型转换器。A null ValueSerializer indicates the type converter should be ignored for convert-to-string conversions from the object graph.

重要

ValueSerializer实现应避免引发异常。Implementation of ValueSerializer should avoid throwing exceptions. 引发的任何异常都可能终止序列化。Any exceptions thrown could terminate serialization.

IValueSerializerContext对于, 其 api ITypeDescriptorContext与适用TypeConverter于。 ValueSerializerIValueSerializerContext for a ValueSerializer and its APIs is analogous to ITypeDescriptorContext for a TypeConverter. 事实上, IValueSerializerContext继承ITypeDescriptorContextIn fact, IValueSerializerContext inherits ITypeDescriptorContext. ValueSerializer调用派生类 API 时, 调用方 (通常是序列化程序进程) 将传递可能提供某些服务的上下文。When a ValueSerializer derived class API is called, the caller (typically a serializer process) passes a context that may provide certain services. 由于一般的指导, ValueSerializer不能引发异常。Because of the general guidance that a ValueSerializer must not throw exceptions. 未能从上下文返回特定服务也必须不会引发任何异常。Failure to return a particular service from the context must also not throw any exceptions.

在 .NET Framework 的以前版本中, 此类存在于 WPF 特定的程序集 WindowsBase 中。In previous versions of the .NET Framework, this class existed in the WPF-specific assembly WindowsBase. .NET Framework 4.NET Framework 4ValueSerializer , 为 system.exception 程序集。In .NET Framework 4.NET Framework 4, ValueSerializer is in the System.Xaml assembly. 有关详细信息,请参阅 Types Migrated from WPF to System.XamlFor more information, see Types Migrated from WPF to System.Xaml.

构造函数

ValueSerializer()

初始化 ValueSerializer 类的新实例。Initializes a new instance of the ValueSerializer class.

方法

CanConvertFromString(String, IValueSerializerContext)

在派生类中重写时,确定指定的 String 能否转换为 ValueSerializer 的实现所支持类型的实例。When overridden in a derived class, determines whether the specified String can be converted to an instance of the type that the implementation of ValueSerializer supports.

CanConvertToString(Object, IValueSerializerContext)

在派生类中重写时,确定指定对象是否可以转换为 StringWhen overridden in a derived class, determines whether the specified object can be converted into a String.

ConvertFromString(String, IValueSerializerContext)

在派生类中重写时,将 String 转换为 ValueSerializer 的实现所支持类型的实例。When overridden in a derived class, converts a String to an instance of the type that the implementation of ValueSerializer supports.

ConvertToString(Object, IValueSerializerContext)

在派生类中重写时,将指定对象转换为 StringWhen overridden in a derived class, converts the specified object to a String.

Equals(Object)

确定指定的对象是否等于当前对象。Determines whether the specified object is equal to the current object.

(继承自 Object)
GetConvertFromException(Object)

返回无法执行转换时引发的异常。Returns an exception to throw when a conversion cannot be performed.

GetConvertToException(Object, Type)

返回无法执行转换时引发的异常。Returns an exception to throw when a conversion cannot be performed.

GetHashCode()

用作默认哈希函数。Serves as the default hash function.

(继承自 Object)
GetSerializerFor(PropertyDescriptor)

通过传递属性的 CLR 属性描述符,获取为该属性声明的 ValueSerializerGets the ValueSerializer declared for a property, by passing a CLR property descriptor for the property.

GetSerializerFor(PropertyDescriptor, IValueSerializerContext)

使用指定的上下文获取为指定的属性声明的 ValueSerializerGets the ValueSerializer declared for the specified property, using the specified context.

GetSerializerFor(Type)

获取为指定的类型声明的 ValueSerializerGets the ValueSerializer declared for the specified type.

GetSerializerFor(Type, IValueSerializerContext)

使用指定的上下文获取为指定的类型声明的 ValueSerializerGets the ValueSerializer declared for the specified type, using the specified context.

GetType()

获取当前实例的 TypeGets the Type of the current instance.

(继承自 Object)
MemberwiseClone()

创建当前 Object 的浅表副本。Creates a shallow copy of the current Object.

(继承自 Object)
ToString()

返回一个表示当前对象的 string。Returns a string that represents the current object.

(继承自 Object)
TypeReferences(Object, IValueSerializerContext)

获取 ValueSerializer 引用的类型的枚举。Gets an enumeration of the types referenced by the ValueSerializer.

适用于

另请参阅