// Copyright (c) All contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using System;
using MessagePack.Formatters;
namespace MessagePack.Resolvers
{
public sealed class NativeDecimalResolver : IFormatterResolver
{
///
/// The singleton instance that can be used.
///
public static readonly NativeDecimalResolver Instance = new NativeDecimalResolver();
private NativeDecimalResolver()
{
}
public IMessagePackFormatter GetFormatter()
{
return FormatterCache.Formatter;
}
private static object GetFormatterHelper(Type t)
{
if (t == typeof(Decimal))
{
return NativeDecimalFormatter.Instance;
}
else if (t == typeof(Decimal?))
{
return new StaticNullableFormatter(NativeDecimalFormatter.Instance);
}
return null;
}
private static class FormatterCache
{
public static readonly IMessagePackFormatter Formatter;
static FormatterCache()
{
Formatter = (IMessagePackFormatter)GetFormatterHelper(typeof(T));
}
}
}
}