Class KnownSerializers
Represents the registry of all serializers. The Default contains system-wide serializers for the current version of the type system. Serializers explicitly registered with this instance are used by all other instances unless an override is specified. When deserializing from a persisted file, the Importer instance returned by the PsiImporter will create its own KnownSerializer instance, and register serializers compatible with the store being open.
Namespace: Microsoft.Psi.Serialization
Assembly: Microsoft.Psi.dll
Syntax
public class KnownSerializers : object
Remarks
The following rules are applied when searching for a suitable serializer:
- registered serializer for the concrete type
- annotated serializer on the concrete type
- registered serializer for the generic type the current type is constructed from
- annotated serializer on the generic type the current type is constructed from
- auto-generated serializer
When deserializing a polymorphic field, the field's object value might have a different type than the declared (static) type of the field (e.g the field is declared as IEnumerable{int} and is assigned an int[]). In such cases the runtime might not be able to find the correct type to use, and can only instantiate the correct deserializer if one of the following is true:
- a serializer has been explicitly registered for the object type or contract using Register<T, TSerializer>(CloningFlags)
- a type has been explicitly registered with an explicit contract name Register<T>(String, CloningFlags) or Register<T, TSerializer>(String, CloningFlags).
Constructors
View SourceKnownSerializers(RuntimeInfo, KnownSerializers)
Initializes a new instance of the KnownSerializers class.
Declaration
public KnownSerializers(RuntimeInfo runtimeInfo = null, KnownSerializers knownSerializers = null)
Parameters
Type | Name | Description |
---|---|---|
RuntimeInfo | runtimeInfo | The version of the runtime to be compatible with. This dictates the behavior of automatic serialization. |
KnownSerializers | knownSerializers | A set of known serializers to initialize with. |
Fields
View SourceDefault
The default set of types and serializer creation rules globally known to the serialization subsystem. Custom serializers can be added directly to this set.
Declaration
public static readonly KnownSerializers Default
Field Value
Type | Description |
---|---|
KnownSerializers |
Properties
View SourceRuntimeInfo
Gets the runtime info, including the version of the serialization subsystem.
Declaration
public RuntimeInfo RuntimeInfo { get; }
Property Value
Type | Description |
---|---|
RuntimeInfo |
Schemas
Gets the set of schemas in use.
Declaration
public IDictionary<string, TypeSchema> Schemas { get; }
Property Value
Type | Description |
---|---|
IDictionary<String, TypeSchema> |
TypeNameSynonyms
Gets the set of type name synonyms.
Declaration
public IDictionary<string, string> TypeNameSynonyms { get; }
Property Value
Type | Description |
---|---|
IDictionary<String, String> |
Methods
View SourceGetHandler<T>()
Gets the serialization handler for a specified type.
Declaration
public SerializationHandler<T> GetHandler<T>()
Returns
Type | Description |
---|---|
SerializationHandler<T> | The serialization handler for a specified type. |
Type Parameters
Name | Description |
---|---|
T | The type to get the serialization handler for. |
Remarks
This is the slow-ish path, called at codegen time, from custom serializers that want to cache a handler and for polymorphic fields, the first time the id is encountered.
Register(Type, String, CloningFlags)
Registers a given type with the specified contract name. Use this overload to deserialize data persisted before a type name change.
Declaration
public void Register(Type type, string contractName, CloningFlags cloningFlags = default(CloningFlags))
Parameters
Type | Name | Description |
---|---|---|
Type | type | The type to use when deserializing objects with the specified contract. |
String | contractName | The name to remap. This can be a full type name or a contract name. |
CloningFlags | cloningFlags | Optional flags that control the cloning behavior for this type. |
Register<T>(CloningFlags)
Registers a type that the serialization system would not be able find or resolve. Use this overload when type T is required in a polymorphic context.
Declaration
public void Register<T>(CloningFlags cloningFlags = default(CloningFlags))
Parameters
Type | Name | Description |
---|---|---|
CloningFlags | cloningFlags | Optional flags that control the cloning behavior for this type. |
Type Parameters
Name | Description |
---|---|
T | The type to serialize. |
Remarks
When deserializing a polymorphic field, the field's object value might have a different type than the declared (static) type of the field (e.g the field is declared as IEnumerable{int} and is assigned a MyCustomCollection{int}). Pre-registering the type allows the runtime to find it in such circumstances.
Register<T>(String, CloningFlags)
Registers type T with the specified contract name. Use this overload to deserialize data persisted before a type name change.
Declaration
public void Register<T>(string contractName, CloningFlags cloningFlags = default(CloningFlags))
Parameters
Type | Name | Description |
---|---|---|
String | contractName | The name to remap. This can be a full type name or a contract name. |
CloningFlags | cloningFlags | Optional flags that control the cloning behavior for this type. |
Type Parameters
Name | Description |
---|---|
T | The type to use when deserializing objects with the specified contract. |
Register<T, TSerializer>(CloningFlags)
Registers a serializer based on type. Use this overload to register a custom implementation of ISerializer<T>.
Declaration
public void Register<T, TSerializer>(CloningFlags cloningFlags = default(CloningFlags))
where TSerializer : ISerializer<T>, new()
Parameters
Type | Name | Description |
---|---|---|
CloningFlags | cloningFlags | Optional flags that control the cloning behavior for this type. |
Type Parameters
Name | Description |
---|---|
T | The type being serialized. |
TSerializer | The corresponding type of serializer to use, which replaces any SerializerAttribute annotation. |
Register<T, TSerializer>(String, CloningFlags)
Registers a type and serializer for the specified contract type. Use this overload to deserialize data persisted before a type name change.
Declaration
public void Register<T, TSerializer>(string contractName, CloningFlags cloningFlags = default(CloningFlags))
where TSerializer : ISerializer<T>, new()
Parameters
Type | Name | Description |
---|---|---|
String | contractName | The previous contract name of type T. |
CloningFlags | cloningFlags | Optional flags that control the cloning behavior for this type. |
Type Parameters
Name | Description |
---|---|
T | The type being serialized. |
TSerializer | The corresponding type of serializer to use, which replaces any SerializerAttribute annotation. |
RegisterDynamicTypeSchemaNameSynonym(String, String)
Register synonym for fully-qualified type name.
Declaration
public void RegisterDynamicTypeSchemaNameSynonym(string synonym, string fullyQualifiedTypeName)
Parameters
Type | Name | Description |
---|---|---|
String | synonym | Synonym used in type-schema info. |
String | fullyQualifiedTypeName | Fully-qualified .NET type name. |
RegisterGenericSerializer(Type)
Registers a generic serializer, that is, a serializer defined for a generic type. The generic serializer must implement ISerializer<T>.
Declaration
public void RegisterGenericSerializer(Type genericSerializer)
Parameters
Type | Name | Description |
---|---|---|
Type | genericSerializer | The type of generic serializer to register. |
Events
View SourceSchemaAdded
Event which fires when each new type schema has been added.
Declaration
public event EventHandler<TypeSchema> SchemaAdded
Event Type
Type | Description |
---|---|
EventHandler<TypeSchema> |