// Copyright (c) All contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using MessagePack.Formatters;
namespace MessagePack.Resolvers
{
public sealed class PrimitiveObjectResolver : IFormatterResolver
{
///
/// The singleton instance that can be used.
///
public static readonly PrimitiveObjectResolver Instance;
///
/// A instance with this formatter pre-configured.
///
public static readonly MessagePackSerializerOptions Options;
static PrimitiveObjectResolver()
{
Instance = new PrimitiveObjectResolver();
Options = new MessagePackSerializerOptions(Instance);
}
private PrimitiveObjectResolver()
{
}
public IMessagePackFormatter GetFormatter()
{
return FormatterCache.Formatter;
}
private static class FormatterCache
{
public static readonly IMessagePackFormatter Formatter;
static FormatterCache()
{
Formatter = (typeof(T) == typeof(object))
? (IMessagePackFormatter)(object)PrimitiveObjectFormatter.Instance
: null;
}
}
}
////#if !UNITY_2018_3_OR_NEWER
//// ///
//// /// In `object`, when serializing resolve by concrete type and when deserializing use primitive.
//// ///
//// public sealed class DynamicObjectTypeFallbackResolver : IFormatterResolver
//// {
//// public static readonly DynamicObjectTypeFallbackResolver Instance = new DynamicObjectTypeFallbackResolver();
//// DynamicObjectTypeFallbackResolver()
//// {
//// }
//// public IMessagePackFormatter GetFormatter()
//// {
//// return FormatterCache.formatter;
//// }
//// static class FormatterCache
//// {
//// public static readonly IMessagePackFormatter formatter;
//// static FormatterCache()
//// {
//// formatter = (typeof(T) == typeof(object))
//// ? (IMessagePackFormatter)(object)DynamicObjectTypeFallbackFormatter.Instance
//// : null;
//// }
//// }
//// }
////#endif
}