diff --git a/Mirror/Weaver/Mirror.Weaver.csproj b/Mirror/Weaver/Mirror.Weaver.csproj
index 4fcad94bc..ec1bdf8d8 100644
--- a/Mirror/Weaver/Mirror.Weaver.csproj
+++ b/Mirror/Weaver/Mirror.Weaver.csproj
@@ -72,6 +72,7 @@
+
diff --git a/Mirror/Weaver/Processors/NetworkBehaviourProcessor.cs b/Mirror/Weaver/Processors/NetworkBehaviourProcessor.cs
index 88f22a2bc..a8f73b05c 100644
--- a/Mirror/Weaver/Processors/NetworkBehaviourProcessor.cs
+++ b/Mirror/Weaver/Processors/NetworkBehaviourProcessor.cs
@@ -266,7 +266,7 @@ void GenerateConstants()
foreach (FieldDefinition fd in m_SyncObjects)
{
- GenerateSyncListInstanceInitializer(ctorWorker, fd);
+ SyncListProcessor.GenerateSyncListInstanceInitializer(ctorWorker, fd);
SyncObjectProcessor.GenerateSyncObjectInitializer(ctorWorker, fd);
}
@@ -283,33 +283,6 @@ void GenerateConstants()
m_td.Attributes = m_td.Attributes & ~TypeAttributes.BeforeFieldInit;
}
- // generates 'syncListInt = new SyncListInt()' if user didn't do that yet
- void GenerateSyncListInstanceInitializer(ILProcessor ctorWorker, FieldDefinition fd)
- {
- // check the ctor's instructions for an Stfld op-code for this specific sync list field.
- foreach (var ins in ctorWorker.Body.Instructions)
- {
- if (ins.OpCode.Code == Code.Stfld)
- {
- var field = (FieldDefinition)ins.Operand;
- if (field.DeclaringType == fd.DeclaringType && field.Name == fd.Name)
- {
- // Already initialized by the user in the field definition, e.g:
- // public SyncListInt Foo = new SyncListInt();
- return;
- }
- }
- }
-
- // Not initialized by the user in the field definition, e.g:
- // public SyncListInt Foo;
- var listCtor = Weaver.scriptDef.MainModule.ImportReference(fd.FieldType.Resolve().Methods.First(x => x.Name == ".ctor" && !x.HasParameters));
-
- ctorWorker.Append(ctorWorker.Create(OpCodes.Ldarg_0));
- ctorWorker.Append(ctorWorker.Create(OpCodes.Newobj, listCtor));
- ctorWorker.Append(ctorWorker.Create(OpCodes.Stfld, fd));
- }
-
/*
// This generates code like:
NetworkBehaviour.RegisterCommandDelegate(base.GetType(), "CmdThrust", new NetworkBehaviour.CmdDelegate(ShipControl.InvokeCmdCmdThrust));
diff --git a/Mirror/Weaver/Processors/SyncListProcessor.cs b/Mirror/Weaver/Processors/SyncListProcessor.cs
new file mode 100644
index 000000000..c3169a1a0
--- /dev/null
+++ b/Mirror/Weaver/Processors/SyncListProcessor.cs
@@ -0,0 +1,37 @@
+// SyncList code
+using System.Linq;
+using Mono.Cecil;
+using Mono.Cecil.Cil;
+
+namespace Mirror.Weaver
+{
+ public static class SyncListProcessor
+ {
+ // generates 'syncListInt = new SyncListInt()' if user didn't do that yet
+ public static void GenerateSyncListInstanceInitializer(ILProcessor ctorWorker, FieldDefinition fd)
+ {
+ // check the ctor's instructions for an Stfld op-code for this specific sync list field.
+ foreach (var ins in ctorWorker.Body.Instructions)
+ {
+ if (ins.OpCode.Code == Code.Stfld)
+ {
+ var field = (FieldDefinition)ins.Operand;
+ if (field.DeclaringType == fd.DeclaringType && field.Name == fd.Name)
+ {
+ // Already initialized by the user in the field definition, e.g:
+ // public SyncListInt Foo = new SyncListInt();
+ return;
+ }
+ }
+ }
+
+ // Not initialized by the user in the field definition, e.g:
+ // public SyncListInt Foo;
+ var listCtor = Weaver.scriptDef.MainModule.ImportReference(fd.FieldType.Resolve().Methods.First(x => x.Name == ".ctor" && !x.HasParameters));
+
+ ctorWorker.Append(ctorWorker.Create(OpCodes.Ldarg_0));
+ ctorWorker.Append(ctorWorker.Create(OpCodes.Newobj, listCtor));
+ ctorWorker.Append(ctorWorker.Create(OpCodes.Stfld, fd));
+ }
+ }
+}
\ No newline at end of file