MsgPack.Serialization.SerializationContext Class Reference

This is intened to MsgPack for CLI internal use. Do not use this type from application directly. Represents serialization context information for internal serialization logic. More...

Public Member Functions

 SerializationContext ()
 Initializes a new instance of the SerializationContext class with copy of SerializerRepository.GetDefault(). More...
 
 SerializationContext (PackerCompatibilityOptions packerCompatibilityOptions)
 Initializes a new instance of the SerializationContext class with copy of SerializerRepository.GetDefault() for specified PackerCompatibilityOptions. More...
 
MessagePackSerializer< T > GetSerializer< T > ()
 Gets the MessagePackSerializer<T> with this instance without provider parameter. More...
 
MessagePackSerializer< T > GetSerializer< T > (object providerParameter)
 Gets the MessagePackSerializer<T> with this instance. More...
 
MessagePackSerializer GetSerializer (Type targetType)
 Gets the serializer for the specified Type. More...
 
MessagePackSerializer GetSerializer (Type targetType, object providerParameter)
 Gets the serializer for the specified Type. More...
 

Static Public Member Functions

static SerializationContext ConfigureClassic ()
 Configures Default as new classic SerializationContext instance. More...
 
static SerializationContext CreateClassicContext ()
 Creates a new SerializationContext which is configured as same as 0.5. More...
 

Properties

static SerializationContext Default [get, set]
 Gets or sets the default instance. More...
 
SerializerRepository Serializers [get]
 Gets the current SerializerRepository. More...
 
SerializerOptions SerializerOptions [get]
 Gets the option settings for serializer generation. More...
 
SerializationCompatibilityOptions CompatibilityOptions [get]
 Gets the compatibility options. More...
 
DictionarySerlaizationOptions DictionarySerlaizationOptions [get]
 Gets the dictionary(map) based serialization options. More...
 
SerializationMethod SerializationMethod [get, set]
 Gets or sets the SerializationMethod to determine serialization strategy. More...
 
EnumSerializationOptions EnumSerializationOptions [get]
 Gets the enum serialization options. More...
 
EnumSerializationMethod EnumSerializationMethod [get, set]
 Gets or sets the EnumSerializationMethod to determine default serialization strategy of enum types. More...
 
SerializationMethodGeneratorOption GeneratorOption [get, set]
 Gets or sets the SerializationMethodGeneratorOption to control code generation. More...
 
DefaultConcreteTypeRepository DefaultCollectionTypes [get]
 Gets the default collection types. More...
 
DateTimeConversionMethod DefaultDateTimeConversionMethod [get, set]
 Gets or sets the default DateTime conversion methods of built-in serializers. More...
 
EventHandler< ResolveSerializerEventArgsResolveSerializer
 Occurs when the context have not find appropriate registered nor built-in serializer for specified type. More...
 
ExtTypeCodeMapping ExtTypeCodeMapping [get]
 Gets the current mapping table of ext type code. More...
 

Detailed Description

This is intened to MsgPack for CLI internal use. Do not use this type from application directly. Represents serialization context information for internal serialization logic.

Constructor & Destructor Documentation

◆ SerializationContext() [1/2]

MsgPack.Serialization.SerializationContext.SerializationContext ( )

Initializes a new instance of the SerializationContext class with copy of SerializerRepository.GetDefault().

◆ SerializationContext() [2/2]

MsgPack.Serialization.SerializationContext.SerializationContext ( PackerCompatibilityOptions  packerCompatibilityOptions)

Initializes a new instance of the SerializationContext class with copy of SerializerRepository.GetDefault() for specified PackerCompatibilityOptions.

Parameters
packerCompatibilityOptionsPackerCompatibilityOptions which will be used on built-in serializers.

Member Function Documentation

◆ ConfigureClassic()

static SerializationContext MsgPack.Serialization.SerializationContext.ConfigureClassic ( )
static

Configures Default as new classic SerializationContext instance.

Returns
The previously set context as Default.
See also
CreateClassicContext()

◆ CreateClassicContext()

static SerializationContext MsgPack.Serialization.SerializationContext.CreateClassicContext ( )
static

Creates a new SerializationContext which is configured as same as 0.5.

Returns
A new SerializationContext which is configured as same as 0.5.

There are breaking changes of SerializationContext properties to improve API usability and to prevent accidental failure. This method returns a SerializationContext which configured as classic style settings as follows:

Default (as of 0.6) Classic (before 0.6)
Packed object members order (if members are not marked with MessagePackMemberAttribute nor System.Runtime.Serialization.DataMemberAttribute and serializer uses F:SerializationMethod.Array) As declared (metadata table order) As lexicographical
DateTime value Native representation (100-nano ticks, preserving DateTimeKind.) UTC, milliseconds Unix epoc.

◆ GetSerializer() [1/2]

MessagePackSerializer MsgPack.Serialization.SerializationContext.GetSerializer ( Type  targetType)

Gets the serializer for the specified Type.

Parameters
targetTypeType of the serialization target.
Returns
MessagePackSerializer. If there is exiting one, returns it. Else the new instance will be created. If the platform supports async/await programming model, return type is IAsyncMessagePackSingleObjectSerializer.
Exceptions
ArgumentNullExceptiontargetType is null.

Although GetSerializer<T>() is preferred, this method can be used from non-generic type or methods.

◆ GetSerializer() [2/2]

MessagePackSerializer MsgPack.Serialization.SerializationContext.GetSerializer ( Type  targetType,
object  providerParameter 
)

Gets the serializer for the specified Type.

Parameters
targetTypeType of the serialization target.
providerParameterA provider specific parameter. See remarks section of GetSerializer<T>(Object) for details.
Returns
MessagePackSerializer. If there is exiting one, returns it. Else the new instance will be created. If the platform supports async/await programming model, return type is IAsyncMessagePackSingleObjectSerializer.
Exceptions
ArgumentNullExceptiontargetType is null.

Although GetSerializer<T>(Object) is preferred, this method can be used from non-generic type or methods.

◆ GetSerializer< T >() [1/2]

Gets the MessagePackSerializer<T> with this instance without provider parameter.

Template Parameters
TType of serialization/deserialization target.
Returns
MessagePackSerializer<T>. If there is exiting one, returns it. Else the new instance will be created.

This method automatically register new instance via SerializerRepository.Register<T>(MessagePackSerializer<T>).

◆ GetSerializer< T >() [2/2]

Gets the MessagePackSerializer<T> with this instance.

Template Parameters
TType of serialization/deserialization target.
Parameters
providerParameterA provider specific parameter. See remarks section for details.
Returns
MessagePackSerializer<T>. If there is exiting one, returns it. Else the new instance will be created.

This method automatically register new instance via SerializerRepository.Register<T>(MessagePackSerializer<T>).

Currently, only following provider parameters are supported.

Target type Provider parameter
EnumMessagePackSerializer<TEnum> or its descendants. EnumSerializationMethod. The returning instance corresponds to this value for serialization.

<note>null is valid value for providerParameter and it indeicates default behavior of parameter.</note>

Property Documentation

◆ CompatibilityOptions

SerializationCompatibilityOptions MsgPack.Serialization.SerializationContext.CompatibilityOptions
get

Gets the compatibility options.

The SerializationCompatibilityOptions which stores compatibility options. This value will not be null.

◆ Default

SerializationContext MsgPack.Serialization.SerializationContext.Default
staticgetset

Gets or sets the default instance.

The default SerializationContext instance.

Exceptions
ArgumentNullExceptionThe setting value is null.

◆ DefaultCollectionTypes

DefaultConcreteTypeRepository MsgPack.Serialization.SerializationContext.DefaultCollectionTypes
get

Gets the default collection types.

The default collection types. This value will not be null.

◆ DefaultDateTimeConversionMethod

DateTimeConversionMethod MsgPack.Serialization.SerializationContext.DefaultDateTimeConversionMethod
getset

Gets or sets the default DateTime conversion methods of built-in serializers.

The default DateTime conversion methods of built-in serializers. The default is F:DateTimeConversionMethod.Native.

Exceptions
ArgumentOutOfRangeExceptionThe setting value is invalid as SerializationMethod enum.

As of 0.6, DateTime value is serialized as its native representation instead of interoperable UTC milliseconds Unix epoc. This behavior solves some debugging problem and interop issues, but breaks compability. If you want to change this behavior, set this value to F:DateTimeConversionMethod.UnixEpoc.

◆ DictionarySerlaizationOptions

DictionarySerlaizationOptions MsgPack.Serialization.SerializationContext.DictionarySerlaizationOptions
get

Gets the dictionary(map) based serialization options.

The DictionarySerlaizationOptions which stores dictionary(map) based serialization options. This value will not be null.

◆ EnumSerializationMethod

EnumSerializationMethod MsgPack.Serialization.SerializationContext.EnumSerializationMethod
getset

Gets or sets the EnumSerializationMethod to determine default serialization strategy of enum types.

The EnumSerializationMethod to determine default serialization strategy of enum types.

Exceptions
ArgumentOutOfRangeExceptionThe setting value is invalid as EnumSerializationMethod enum.

<note>This property is wrapper for Serialization.EnumSerializationOptions.SerializationMethod property.</note> A serialization strategy for specific member is determined as following:

Note that the default value of this property is T:EnumSerializationMethod.ByName, it is not size efficient but tolerant to unexpected enum definition change.

◆ EnumSerializationOptions

EnumSerializationOptions MsgPack.Serialization.SerializationContext.EnumSerializationOptions
get

Gets the enum serialization options.

The Serialization.EnumSerializationOptions which stores enum serialization options. This value will not be null.

◆ ExtTypeCodeMapping

ExtTypeCodeMapping MsgPack.Serialization.SerializationContext.ExtTypeCodeMapping
get

Gets the current mapping table of ext type code.

The ExtTypeCodeMapping which maps between known ext type names and ext type codes.

◆ GeneratorOption

SerializationMethodGeneratorOption MsgPack.Serialization.SerializationContext.GeneratorOption
getset

Gets or sets the SerializationMethodGeneratorOption to control code generation.

Exceptions
ArgumentOutOfRangeExceptionThe setting value is invalid as SerializationMethodGeneratorOption enum.

The SerializationMethodGeneratorOption.

◆ ResolveSerializer

EventHandler<ResolveSerializerEventArgs> MsgPack.Serialization.SerializationContext.ResolveSerializer
addremove

Occurs when the context have not find appropriate registered nor built-in serializer for specified type.

This event will be occured when the context could not found known serializer from:

  • Known built-in serializers for arrays, nullables, and collections, etc.
  • Known default serializers for some known various FCL value types and some reference types.
  • Previously registered or generated serializer.

You can instantiate your custom serializer using various ResolveSerializerEventArgs properties, and then call ResolveSerializerEventArgs.SetSerializer<T> to provide toward the context. <note> You can use SerializationContext to get dependent serializers as you like, but you should never explicitly register new serializer(s) explicitly via the context from the event handler and its dependents. Instead, you specify the instanciated serializer with ResolveSerializerEventArgs.SetSerializer<T> once at a time. Dependent serializer(s) should be registered via next (nested) raise of this event. </note> <note> The context implicitly holds 'lock' for the target type for the requested serializer in the current thread. So you should not use any synchronization primitives in the event handler and its dependents, or you may face complex dead lock. That is, the event handler should be as simple as possible like just instanciate the serializer and set it to the event argument. </note>

◆ SerializationMethod

SerializationMethod MsgPack.Serialization.SerializationContext.SerializationMethod
getset

Gets or sets the SerializationMethod to determine serialization strategy.

The SerializationMethod to determine serialization strategy.

Exceptions
ArgumentOutOfRangeExceptionThe setting value is invalid as SerializationMethod enum.

◆ SerializerOptions

SerializerOptions MsgPack.Serialization.SerializationContext.SerializerOptions
get

Gets the option settings for serializer generation.

The option settings for serializer generation. This value will not be null.

◆ Serializers

SerializerRepository MsgPack.Serialization.SerializationContext.Serializers
get

Gets the current SerializerRepository.

The current SerializerRepository.


The documentation for this class was generated from the following files:
  • MsgPackSources/Serialization/SerializationContext.cs
  • MsgPackSources/Serialization/SerializationContext.ExtTypeCodes.cs