Created
August 3, 2017 13:34
-
-
Save nemotoo/1c349f1d6c245460724404f181f4539a to your computer and use it in GitHub Desktop.
Skeleton of mpc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma warning disable 618 | |
#pragma warning disable 612 | |
#pragma warning disable 414 | |
#pragma warning disable 168 | |
namespace MessagePack.Resolvers | |
{ | |
using System; | |
using MessagePack; | |
public class GeneratedResolver : global::MessagePack.IFormatterResolver | |
{ | |
public static readonly global::MessagePack.IFormatterResolver Instance = new GeneratedResolver(); | |
GeneratedResolver() | |
{ | |
} | |
public global::MessagePack.Formatters.IMessagePackFormatter<T> GetFormatter<T>() | |
{ | |
return FormatterCache<T>.formatter; | |
} | |
static class FormatterCache<T> | |
{ | |
public static readonly global::MessagePack.Formatters.IMessagePackFormatter<T> formatter; | |
static FormatterCache() | |
{ | |
var f = GeneratedResolverGetFormatterHelper.GetFormatter(typeof(T)); | |
if (f != null) | |
{ | |
formatter = (global::MessagePack.Formatters.IMessagePackFormatter<T>)f; | |
} | |
} | |
} | |
} | |
internal static class GeneratedResolverGetFormatterHelper | |
{ | |
static readonly global::System.Collections.Generic.Dictionary<Type, int> lookup; | |
static GeneratedResolverGetFormatterHelper() | |
{ | |
lookup = new global::System.Collections.Generic.Dictionary<Type, int>(0) | |
{ | |
}; | |
} | |
internal static object GetFormatter(Type t) | |
{ | |
int key; | |
if (!lookup.TryGetValue(t, out key)) return null; | |
switch (key) | |
{ | |
default: return null; | |
} | |
} | |
} | |
} | |
#pragma warning disable 168 | |
#pragma warning restore 414 | |
#pragma warning restore 618 | |
#pragma warning restore 612 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment