Fix SignalR messagepack formatter potentially initializing on iOS

This commit is contained in:
Salman Ahmed 2021-11-19 19:03:52 +03:00
parent d397524878
commit 0342923408
1 changed files with 4 additions and 2 deletions

View File

@ -35,7 +35,9 @@ public class SignalRUnionWorkaroundResolver : IFormatterResolver
typeof(TeamVersusUserState),
};
private static readonly IReadOnlyDictionary<Type, IMessagePackFormatter> formatter_map = new Dictionary<Type, IMessagePackFormatter>
private static IReadOnlyDictionary<Type, IMessagePackFormatter> formatterMapBacking;
private static IReadOnlyDictionary<Type, IMessagePackFormatter> formatterMap => formatterMapBacking ??= new Dictionary<Type, IMessagePackFormatter>
{
{ typeof(TeamVersusUserState), new TypeRedirectingFormatter<TeamVersusUserState, MatchUserState>() },
{ typeof(TeamVersusRoomState), new TypeRedirectingFormatter<TeamVersusRoomState, MatchRoomState>() },
@ -51,7 +53,7 @@ public class SignalRUnionWorkaroundResolver : IFormatterResolver
public IMessagePackFormatter<T> GetFormatter<T>()
{
if (formatter_map.TryGetValue(typeof(T), out var formatter))
if (formatterMap.TryGetValue(typeof(T), out var formatter))
return (IMessagePackFormatter<T>)formatter;
return StandardResolver.Instance.GetFormatter<T>();