static void LoadDeclaredWriters(AssemblyDefinition currentAssembly, TypeDefinition klass) { // register all the writers in this class. Skip the ones with wrong signature foreach (MethodDefinition method in klass.Methods) { if (method.Parameters.Count != 2) { continue; } if (!method.Parameters[0].ParameterType.Is <NetworkWriter>()) { continue; } if (!method.ReturnType.Is(typeof(void))) { continue; } if (!method.HasCustomAttribute <System.Runtime.CompilerServices.ExtensionAttribute>()) { continue; } if (method.HasGenericParameters) { continue; } TypeReference dataType = method.Parameters[1].ParameterType; Writers.Register(dataType, currentAssembly.MainModule.ImportReference(method)); } }
static void LoadWriters(AssemblyDefinition currentAssembly, TypeDefinition klass) { // register all the writers in this class. Skip the ones with wrong signature foreach (MethodDefinition method in klass.Methods) { if (method.Parameters.Count != 2) { continue; } if (method.Parameters[0].ParameterType.FullName != "Mirror.NetworkWriter") { continue; } if (method.ReturnType.FullName != "System.Void") { continue; } if (method.GetCustomAttribute("System.Runtime.CompilerServices.ExtensionAttribute") == null) { continue; } TypeReference dataType = method.Parameters[1].ParameterType; Writers.Register(dataType, currentAssembly.MainModule.ImportReference(method)); } }
private void RegisterWriter(MethodInfo method) { if (method.GetParameters().Length != 2) { return; } if (method.GetParameters()[0].ParameterType.FullName != typeof(NetworkWriter).FullName) { return; } if (method.ReturnType != typeof(void)) { return; } Type dataType = method.GetParameters()[1].ParameterType; writers.Register(module.ImportReference(dataType), module.ImportReference(method)); }