Initial Commit (broken due to version update)
This commit is contained in:
parent
74003df84b
commit
3f7b3b7440
3132 changed files with 1103305 additions and 0 deletions
60
Assets/Scripts/MessagePack/IFormatterResolver.cs
Normal file
60
Assets/Scripts/MessagePack/IFormatterResolver.cs
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
|
||||
using MessagePack.Formatters;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
|
||||
namespace MessagePack
|
||||
{
|
||||
public interface IFormatterResolver
|
||||
{
|
||||
IMessagePackFormatter<T> GetFormatter<T>();
|
||||
}
|
||||
|
||||
public static class FormatterResolverExtensions
|
||||
{
|
||||
public static IMessagePackFormatter<T> GetFormatterWithVerify<T>(this IFormatterResolver resolver)
|
||||
{
|
||||
IMessagePackFormatter<T> formatter;
|
||||
try
|
||||
{
|
||||
formatter = resolver.GetFormatter<T>();
|
||||
}
|
||||
catch (TypeInitializationException ex)
|
||||
{
|
||||
Exception inner = ex;
|
||||
while (inner.InnerException != null)
|
||||
{
|
||||
inner = inner.InnerException;
|
||||
}
|
||||
|
||||
throw inner;
|
||||
}
|
||||
|
||||
if (formatter == null)
|
||||
{
|
||||
throw new FormatterNotRegisteredException(typeof(T).FullName + " is not registered in this resolver. resolver:" + resolver.GetType().Name);
|
||||
}
|
||||
|
||||
return formatter;
|
||||
}
|
||||
|
||||
#if !UNITY_WSA
|
||||
|
||||
public static object GetFormatterDynamic(this IFormatterResolver resolver, Type type)
|
||||
{
|
||||
var methodInfo = typeof(IFormatterResolver).GetRuntimeMethod("GetFormatter", Type.EmptyTypes);
|
||||
|
||||
var formatter = methodInfo.MakeGenericMethod(type).Invoke(resolver, null);
|
||||
return formatter;
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
public class FormatterNotRegisteredException : Exception
|
||||
{
|
||||
public FormatterNotRegisteredException(string message) : base(message)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue