Writers: remove static Log references

This commit is contained in:
vis2k 2021-08-19 22:47:30 +08:00
parent 20405c76f9
commit 7320cd8a2f
2 changed files with 6 additions and 5 deletions

View File

@ -21,7 +21,7 @@ public static bool Process(AssemblyDefinition CurrentAssembly, WeaverTypes weave
// otherwise we would get // otherwise we would get
// "System.ArgumentException: Member ... is declared in another module and needs to be imported" // "System.ArgumentException: Member ... is declared in another module and needs to be imported"
// errors when still using the previous module's reader/writer funcs. // errors when still using the previous module's reader/writer funcs.
writers = new Writers(CurrentAssembly, weaverTypes); writers = new Writers(CurrentAssembly, weaverTypes, Log);
readers = new Readers(CurrentAssembly, weaverTypes, Log); readers = new Readers(CurrentAssembly, weaverTypes, Log);
foreach (Assembly unityAsm in CompilationPipeline.GetAssemblies()) foreach (Assembly unityAsm in CompilationPipeline.GetAssemblies())

View File

@ -13,16 +13,17 @@ public class Writers
// can't be used from another assembly, otherwise we will get: // can't be used from another assembly, otherwise we will get:
// "System.ArgumentException: Member ... is declared in another module and needs to be imported" // "System.ArgumentException: Member ... is declared in another module and needs to be imported"
AssemblyDefinition assembly; AssemblyDefinition assembly;
WeaverTypes weaverTypes; WeaverTypes weaverTypes;
Logger Log;
Dictionary<TypeReference, MethodReference> writeFuncs = Dictionary<TypeReference, MethodReference> writeFuncs =
new Dictionary<TypeReference, MethodReference>(new TypeReferenceComparer()); new Dictionary<TypeReference, MethodReference>(new TypeReferenceComparer());
public Writers(AssemblyDefinition assembly, WeaverTypes weaverTypes) public Writers(AssemblyDefinition assembly, WeaverTypes weaverTypes, Logger Log)
{ {
this.assembly = assembly; this.assembly = assembly;
this.weaverTypes = weaverTypes; this.weaverTypes = weaverTypes;
this.Log = Log;
} }
public void Register(TypeReference dataType, MethodReference methodReference) public void Register(TypeReference dataType, MethodReference methodReference)
@ -64,7 +65,7 @@ public MethodReference GetWriteFunc(TypeReference variable)
} }
catch (GenerateWriterException e) catch (GenerateWriterException e)
{ {
Weaver.Log.Error(e.Message, e.MemberReference); Log.Error(e.Message, e.MemberReference);
Weaver.WeavingFailed = true; Weaver.WeavingFailed = true;
return null; return null;
} }
@ -279,7 +280,7 @@ MethodDefinition GenerateCollectionWriter(TypeReference variable, TypeReference
// need this null check till later PR when GetWriteFunc throws exception instead // need this null check till later PR when GetWriteFunc throws exception instead
if (elementWriteFunc == null) if (elementWriteFunc == null)
{ {
Weaver.Log.Error($"Cannot generate writer for {variable}. Use a supported type or provide a custom writer", variable); Log.Error($"Cannot generate writer for {variable}. Use a supported type or provide a custom writer", variable);
Weaver.WeavingFailed = true; Weaver.WeavingFailed = true;
return writerFunc; return writerFunc;
} }