using MessagePack.Formatters; using MessagePack.Internal; using System; namespace MessagePack.Resolvers { public sealed class NativeDateTimeResolver : IFormatterResolver { public static readonly IFormatterResolver Instance = new NativeDateTimeResolver(); NativeDateTimeResolver() { } public IMessagePackFormatter GetFormatter() { return FormatterCache.formatter; } static class FormatterCache { public static readonly IMessagePackFormatter formatter; static FormatterCache() { formatter = (IMessagePackFormatter)NativeDateTimeResolverGetFormatterHelper.GetFormatter(typeof(T)); } } } } namespace MessagePack.Internal { internal static class NativeDateTimeResolverGetFormatterHelper { internal static object GetFormatter(Type t) { if (t == typeof(DateTime)) { return NativeDateTimeFormatter.Instance; } else if (t == typeof(DateTime?)) { return new StaticNullableFormatter(NativeDateTimeFormatter.Instance); } else if (t == typeof(DateTime[])) { return NativeDateTimeArrayFormatter.Instance; } return null; } } }