Table of Contents

Class ValueSerializer

Namespace
Alternet.UI.Markup
Assembly
Alternet.UI.dll

ValueSerializer allows a type to declare a serializer to control how the type is serialized to and from strings. If a TypeConverter is declared for a type that converts to and from a string, a default value serializer will be created for the type. The string values must be loss-less (i.e. converting to and from a string doesn't loose data) and must be stable (i.e. returns the same string for the same value). If a type converter doesn't meet these requirements, a custom ValueSerializer must be declared that meet the requirements or associate a null ValueSerializer with the type to indicate the type converter should be ignored. Implementation of ValueSerializer should avoid throwing exceptions. Any exceptions thrown could possibly terminate serialization.

public abstract class ValueSerializer
Inheritance
ValueSerializer
Derived

Constructors

ValueSerializer()

Constructor for a ValueSerializer

Methods

CanConvertFromString(string, IValueSerializerContext)

Returns true if the given value can be converted from a string.

CanConvertToString(object, IValueSerializerContext)

Returns true if the given value can be converted to a string.

ConvertFromString(string, IValueSerializerContext)

Convert a string to an object. This method should only be called if CanConvertFromString returns true for the given string.

ConvertToString(object, IValueSerializerContext)

Converts the given value to a string for use in serialization. This method should only be called if CanConvertToString returns true for the given value.

GetConvertFromException(object)

Return a exception to throw if the string cannot be converted

GetConvertToException(object, Type)

Return a exception to throw if the value cannot be converted

GetSerializerFor(PropertyDescriptor)

Get the value serializer declared for the given property. ValueSerializer can be overriden by an attribute on the property declaration.

GetSerializerFor(PropertyDescriptor, IValueSerializerContext)

Get the value serializer declared for the given property. ValueSerializer can be overriden by an attribute on the property declaration. This version should be called whenever the caller has a IValueSerializerContext to ensure that the correct value serializer is returned for the given context.

GetSerializerFor(Type)

Get the value serializer declared for the given type.

GetSerializerFor(Type, IValueSerializerContext)

Get the value serializer declared for the given type. This version should be called whenever the caller has a IValueSerializerContext to ensure that the correct value serializer is returned for the given context.

TypeReferences(object, IValueSerializerContext)

Returns an enumeration of the types referenced by the value serializer. If the value serializer asks for a value serializer for System.Type, any types it asks to convert should be supplied in the returned enumeration. This allows a serializer to ensure a de-serializer has enough information about the types this serializer converts.

Since a value serializer doesn't exist by default, it is important the value serializer be requested from the IValueSerializerContext, not ValueSerializer.GetSerializerFor. This allows a serializer to encode context information (such as xmlns definitions) to the System.Type converter (for example, which prefix to generate).