using MessagePack.Formatters; namespace MessagePack.Resolvers { public sealed class PrimitiveObjectResolver : IFormatterResolver { public static IFormatterResolver Instance = new PrimitiveObjectResolver(); PrimitiveObjectResolver() { } public IMessagePackFormatter GetFormatter() { return FormatterCache.formatter; } static class FormatterCache { public static readonly IMessagePackFormatter formatter; static FormatterCache() { formatter = (typeof(T) == typeof(object)) ? (IMessagePackFormatter)(object)PrimitiveObjectFormatter.Instance : null; } } } //#if NETSTANDARD1_4 // /// // /// In `object`, when serializing resolve by concrete type and when deserializing use primitive. // /// // public sealed class DynamicObjectTypeFallbackResolver : IFormatterResolver // { // public static IFormatterResolver 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 }