贺州人民医院电子沙盘
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

65 lines
1.7 KiB

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