Skip to content

Instantly share code, notes, and snippets.

@nemotoo
Created August 3, 2017 13:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nemotoo/1c349f1d6c245460724404f181f4539a to your computer and use it in GitHub Desktop.
Save nemotoo/1c349f1d6c245460724404f181f4539a to your computer and use it in GitHub Desktop.
Skeleton of mpc
#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