using MessagePack.Formatters; using MessagePack.Internal; using System; namespace MessagePack.Resolvers { public sealed class OldSpecResolver : IFormatterResolver { public static readonly IFormatterResolver Instance = new OldSpecResolver(); OldSpecResolver() { } public IMessagePackFormatter GetFormatter() { return FormatterCache.formatter; } static class FormatterCache { public static readonly IMessagePackFormatter formatter; static FormatterCache() { formatter = (IMessagePackFormatter)OldSpecResolverGetFormatterHelper.GetFormatter(typeof(T)); } } } } namespace MessagePack.Internal { internal static class OldSpecResolverGetFormatterHelper { internal static object GetFormatter(Type t) { if (t == typeof(string)) { return OldSpecStringFormatter.Instance; } else if (t == typeof(string[])) { return new ArrayFormatter(); } else if (t == typeof(byte[])) { return OldSpecBinaryFormatter.Instance; } return null; } } }