// 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 NativeGuidResolver : IFormatterResolver { /// /// The singleton instance that can be used. /// public static readonly NativeGuidResolver Instance = new NativeGuidResolver(); private NativeGuidResolver() { } public IMessagePackFormatter GetFormatter() { return FormatterCache.Formatter; } private static object GetFormatterHelper(Type t) { if (t == typeof(Guid)) { return NativeGuidFormatter.Instance; } else if (t == typeof(Guid?)) { return new StaticNullableFormatter(NativeGuidFormatter.Instance); } return null; } private static class FormatterCache { public static readonly IMessagePackFormatter Formatter; static FormatterCache() { Formatter = (IMessagePackFormatter)GetFormatterHelper(typeof(T)); } } } }