refactor: Move readerFunc to readers class

This commit is contained in:
Paul Pacheco 2019-04-07 11:24:13 -05:00
parent bf6278a28b
commit 53b3f435a3
2 changed files with 5 additions and 5 deletions

View File

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using Mono.Cecil;
using Mono.Cecil.Cil;
@ -8,6 +9,7 @@ namespace Mirror.Weaver
public static class Readers
{
const int MaxRecursionCount = 128;
public static Dictionary<string, MethodReference> readFuncs;
public static MethodReference GetReadFunc(TypeReference variable, int recursionCount = 0)
{
@ -17,7 +19,7 @@ public static MethodReference GetReadFunc(TypeReference variable, int recursionC
return null;
}
if (Weaver.WeaveLists.readFuncs.TryGetValue(variable.FullName, out MethodReference foundFunc))
if (readFuncs.TryGetValue(variable.FullName, out MethodReference foundFunc))
{
if (foundFunc.ReturnType.IsArray == variable.IsArray)
{
@ -72,7 +74,7 @@ public static MethodReference GetReadFunc(TypeReference variable, int recursionC
static void RegisterReadFunc(string name, MethodDefinition newReaderFunc)
{
Weaver.WeaveLists.readFuncs[name] = newReaderFunc;
readFuncs[name] = newReaderFunc;
Weaver.WeaveLists.generatedReadFunctions.Add(newReaderFunc);
Weaver.ConfirmGeneratedCodeClass();

View File

@ -24,8 +24,6 @@ class WeaverLists
// [SyncEvent] invoke functions that should be replaced. dict<originalEventName, replacement>
public Dictionary<string, MethodDefinition> replaceEvents = new Dictionary<string, MethodDefinition>();
public Dictionary<string, MethodReference> readFuncs;
public List<MethodDefinition> generatedReadFunctions = new List<MethodDefinition>();
public List<MethodDefinition> generatedWriteFunctions = new List<MethodDefinition>();
@ -385,7 +383,7 @@ static void SetupTargetTypes()
static void SetupReadFunctions()
{
WeaveLists.readFuncs = new Dictionary<string, MethodReference>
Readers.readFuncs = new Dictionary<string, MethodReference>
{
{ singleType.FullName, Resolvers.ResolveMethod(NetworkReaderType, CurrentAssembly, "ReadSingle") },
{ doubleType.FullName, Resolvers.ResolveMethod(NetworkReaderType, CurrentAssembly, "ReadDouble") },