From 38699528f0b49b569459bd34819a939667e02c85 Mon Sep 17 00:00:00 2001 From: Andreas Pardeike Date: Mon, 12 Feb 2024 19:49:30 +0100 Subject: [PATCH] more cleanup & speed up PatchCategory(...) --- Harmony/Internal/CodeTranspiler.cs | 12 +++++----- Harmony/Internal/InlineSignatureParser.cs | 2 +- Harmony/Internal/MethodCopier.cs | 2 +- Harmony/Internal/MethodPatcher.cs | 6 ++--- Harmony/Internal/PatchFunctions.cs | 2 +- Harmony/Internal/PatchTools.cs | 1 - Harmony/Public/Attributes.cs | 2 +- Harmony/Public/CodeInstruction.cs | 6 ++--- Harmony/Public/ExceptionBlock.cs | 20 ++++++---------- Harmony/Public/Harmony.cs | 11 +++++---- Harmony/Public/HarmonyException.cs | 2 +- Harmony/Public/HarmonyMethod.cs | 2 +- Harmony/Public/Patch.cs | 20 +++++++++------- Harmony/Public/PatchClassProcessor.cs | 8 +++---- Harmony/Public/PatchJsonConverter.cs | 2 +- Harmony/Public/PatchProcessor.cs | 22 +++++++---------- Harmony/Public/ReversePatcher.cs | 25 +++++++------------- Harmony/Tools/AccessTools.cs | 16 ++++++------- HarmonyTests/IL/DynamicArgumentPatches.cs | 2 +- HarmonyTests/Patching/Assets/PatchClasses.cs | 2 +- HarmonyTests/Patching/InternalPatches.cs | 4 ++-- TestLibrary/TestPatch.cs | 4 ++-- 22 files changed, 79 insertions(+), 94 deletions(-) diff --git a/Harmony/Internal/CodeTranspiler.cs b/Harmony/Internal/CodeTranspiler.cs index dc9cc775..3bfc240b 100644 --- a/Harmony/Internal/CodeTranspiler.cs +++ b/Harmony/Internal/CodeTranspiler.cs @@ -75,7 +75,7 @@ internal static bool ShouldAddExceptionInfo(object op, int opIndex, List if (unassigned.TryGetValue(nameof(CodeInstruction.blocks), out blocksObject) is false) return false; blocks = blocksObject as List; - return blocks.Any(); + return blocks.Count > 0; }); if (pairInstruction is not null) { @@ -92,7 +92,7 @@ internal static bool ShouldAddExceptionInfo(object op, int opIndex, List if (unassigned.TryGetValue(nameof(CodeInstruction.blocks), out blocksObject) is false) return false; blocks = blocksObject as List; - return blocks.Any(); + return blocks.Count > 0; }); if (pairInstruction is not null) { @@ -100,7 +100,7 @@ internal static bool ShouldAddExceptionInfo(object op, int opIndex, List pairEnd = pairStart + newInstructions.Skip(opIndex + 1).ToList().IndexOf(pairInstruction) - 1; var newBetweenInstructions = newInstructions.GetRange(pairStart, pairEnd - pairStart); var remaining = originalBetweenInstructions.Except(newBetweenInstructions).ToList(); - return remaining.Any() is false; + return remaining.Count == 0; } } } @@ -113,7 +113,7 @@ internal static bool ShouldAddExceptionInfo(object op, int opIndex, List if (unassigned.TryGetValue(nameof(CodeInstruction.blocks), out blocksObject) is false) return false; blocks = blocksObject as List; - return blocks.Any(); + return blocks.Count > 0; }); if (pairInstruction is not null) { @@ -130,7 +130,7 @@ internal static bool ShouldAddExceptionInfo(object op, int opIndex, List if (unassigned.TryGetValue(nameof(CodeInstruction.blocks), out blocksObject) is false) return false; blocks = blocksObject as List; - return blocks.Any(); + return blocks.Count > 0; }); if (pairInstruction is not null) { @@ -240,7 +240,7 @@ internal List GetResult(ILGenerator generator, MethodBase metho // call the transpiler var parameter = GetTranspilerCallParameters(generator, transpiler, method, instructions); - var newInstructions = transpiler.Invoke(null, parameter.ToArray()) as IEnumerable; + var newInstructions = transpiler.Invoke(null, [.. parameter]) as IEnumerable; if (newInstructions is object) instructions = newInstructions; diff --git a/Harmony/Internal/InlineSignatureParser.cs b/Harmony/Internal/InlineSignatureParser.cs index 282e7b2a..9a5b2585 100644 --- a/Harmony/Internal/InlineSignatureParser.cs +++ b/Harmony/Internal/InlineSignatureParser.cs @@ -189,7 +189,7 @@ object ReadTypeSignature() throw new NotSupportedException($"Unsupported generic callsite element: {etype}"); case MetadataType.GenericInstance: - reader.ReadByte(); // element type, unused + _ = reader.ReadByte(); // element type, unused var elType = GetTypeDefOrRef(); var arity = (int)ReadCompressedUInt32(); diff --git a/Harmony/Internal/MethodCopier.cs b/Harmony/Internal/MethodCopier.cs index 16ed6999..0f93b1c4 100644 --- a/Harmony/Internal/MethodCopier.cs +++ b/Harmony/Internal/MethodCopier.cs @@ -52,7 +52,7 @@ internal static List GetInstructions(ILGenerator generator, Met var info = Harmony.GetPatchInfo(method); if (info is not null) { - var sortedTranspilers = PatchFunctions.GetSortedPatchMethods(method, info.Transpilers.ToArray(), false); + var sortedTranspilers = PatchFunctions.GetSortedPatchMethods(method, [.. info.Transpilers], false); for (var i = 0; i < maxTranspilers && i < sortedTranspilers.Count; i++) copier.AddTranspiler(sortedTranspilers[i]); } diff --git a/Harmony/Internal/MethodPatcher.cs b/Harmony/Internal/MethodPatcher.cs index 67cb4991..877a9756 100644 --- a/Harmony/Internal/MethodPatcher.cs +++ b/Harmony/Internal/MethodPatcher.cs @@ -114,7 +114,7 @@ internal MethodInfo CreateReplacement(out Dictionary final }); LocalBuilder finalizedVariable = null; - if (finalizers.Any()) + if (finalizers.Count > 0) { finalizedVariable = DeclareLocalVariable(typeof(bool)); @@ -155,7 +155,7 @@ internal MethodInfo CreateReplacement(out Dictionary final var needsToStorePassthroughResult = AddPostfixes(privateVars, runOriginalVariable, true); - var hasFinalizers = finalizers.Any(); + var hasFinalizers = finalizers.Count > 0; if (hasFinalizers) { if (needsToStorePassthroughResult) @@ -244,7 +244,7 @@ internal static DynamicMethodDefinition CreateDynamicMethod(MethodBase original, var method = new DynamicMethodDefinition( patchName, returnType, - parameterTypes.ToArray() + [.. parameterTypes] ) { // OwnerType = original.DeclaringType diff --git a/Harmony/Internal/PatchFunctions.cs b/Harmony/Internal/PatchFunctions.cs index f1e7de5a..e8e5c533 100644 --- a/Harmony/Internal/PatchFunctions.cs +++ b/Harmony/Internal/PatchFunctions.cs @@ -61,7 +61,7 @@ internal static MethodInfo ReversePatch(HarmonyMethod standin, MethodBase origin if (standin.reversePatchType == HarmonyReversePatchType.Snapshot) { var info = Harmony.GetPatchInfo(original); - transpilers.AddRange(GetSortedPatchMethods(original, info.Transpilers.ToArray(), debug)); + transpilers.AddRange(GetSortedPatchMethods(original, [.. info.Transpilers], debug)); } if (postTranspiler is not null) transpilers.Add(postTranspiler); diff --git a/Harmony/Internal/PatchTools.cs b/Harmony/Internal/PatchTools.cs index aa16ff11..b96a6537 100644 --- a/Harmony/Internal/PatchTools.cs +++ b/Harmony/Internal/PatchTools.cs @@ -14,7 +14,6 @@ internal static class PatchTools private static readonly Dictionary detours = []; internal static readonly string harmonyMethodFullName = typeof(HarmonyMethod).FullName; internal static readonly string harmonyAttributeFullName = typeof(HarmonyAttribute).FullName; - internal static readonly string harmonyPatchCategoryFullName = typeof(HarmonyPatchCategory).FullName; internal static readonly string harmonyPatchAllFullName = typeof(HarmonyPatchAll).FullName; internal static void DetourMethod(MethodBase method, MethodBase replacement) diff --git a/Harmony/Public/Attributes.cs b/Harmony/Public/Attributes.cs index 55dda224..06b03666 100644 --- a/Harmony/Public/Attributes.cs +++ b/Harmony/Public/Attributes.cs @@ -361,7 +361,7 @@ void ParseSpecialArguments(Type[] argumentTypes, ArgumentType[] argumentVariatio } types.Add(type); } - info.argumentTypes = types.ToArray(); + info.argumentTypes = [.. types]; } } diff --git a/Harmony/Public/CodeInstruction.cs b/Harmony/Public/CodeInstruction.cs index d214e87c..257210d6 100644 --- a/Harmony/Public/CodeInstruction.cs +++ b/Harmony/Public/CodeInstruction.cs @@ -54,8 +54,8 @@ public CodeInstruction(CodeInstruction instruction) { opcode = instruction.opcode; operand = instruction.operand; - labels = instruction.labels.ToList(); - blocks = instruction.blocks.ToList(); + labels = [.. instruction.labels]; + blocks = [.. instruction.blocks]; } // --- CLONING @@ -316,7 +316,7 @@ public override string ToString() foreach (var block in blocks) list.Add($"EX_{block.blockType.ToString().Replace("Block", "")}"); - var extras = list.Count > 0 ? $" [{string.Join(", ", list.ToArray())}]" : ""; + var extras = list.Count > 0 ? $" [{string.Join(", ", [.. list])}]" : ""; var operandStr = Emitter.FormatArgument(operand); if (operandStr.Length > 0) operandStr = " " + operandStr; return opcode + operandStr + extras; diff --git a/Harmony/Public/ExceptionBlock.cs b/Harmony/Public/ExceptionBlock.cs index 61d060dc..9a42891c 100644 --- a/Harmony/Public/ExceptionBlock.cs +++ b/Harmony/Public/ExceptionBlock.cs @@ -33,24 +33,18 @@ public enum ExceptionBlockType /// An exception block /// - public class ExceptionBlock + /// Creates an exception block + /// The + /// The catch type + /// + public class ExceptionBlock(ExceptionBlockType blockType, Type catchType = null) { /// Block type /// - public ExceptionBlockType blockType; + public ExceptionBlockType blockType = blockType; /// Catch type /// - public Type catchType; - - /// Creates an exception block - /// The - /// The catch type - /// - public ExceptionBlock(ExceptionBlockType blockType, Type catchType = null) - { - this.blockType = blockType; - this.catchType = catchType ?? typeof(object); - } + public Type catchType = catchType ?? typeof(object); } } diff --git a/Harmony/Public/Harmony.cs b/Harmony/Public/Harmony.cs index f52f8b4f..a5f2655a 100644 --- a/Harmony/Public/Harmony.cs +++ b/Harmony/Public/Harmony.cs @@ -153,10 +153,13 @@ public void PatchCategory(string category) public void PatchCategory(Assembly assembly, string category) { AccessTools.GetTypesFromAssembly(assembly) - .Where(type => type.GetCustomAttributes(true).Any(a => a.GetType().FullName == PatchTools.harmonyPatchCategoryFullName)) - .Select(CreateClassProcessor) - .Where(patchClass => patchClass.Category == category) - .Do(patchClass => patchClass.Patch()); + .Where(type => + { + var harmonyAttributes = HarmonyMethodExtensions.GetFromType(type); + var containerAttributes = HarmonyMethod.Merge(harmonyAttributes); + return containerAttributes.category == category; + }) + .Do(type => CreateClassProcessor(type).Patch()); } /// Creates patches by manually specifying the methods diff --git a/Harmony/Public/HarmonyException.cs b/Harmony/Public/HarmonyException.cs index 364143d3..26ba2502 100644 --- a/Harmony/Public/HarmonyException.cs +++ b/Harmony/Public/HarmonyException.cs @@ -53,7 +53,7 @@ internal static Exception Create(Exception ex, Dictionary /// public List> GetInstructionsWithOffsets() { - return instructions.OrderBy(ins => ins.Key).ToList(); + return [.. instructions.OrderBy(ins => ins.Key)]; } /// Get a list of IL instructions without offsets diff --git a/Harmony/Public/HarmonyMethod.cs b/Harmony/Public/HarmonyMethod.cs index 7c69eafb..9a0ac2e7 100644 --- a/Harmony/Public/HarmonyMethod.cs +++ b/Harmony/Public/HarmonyMethod.cs @@ -153,7 +153,7 @@ public static List HarmonyFields() public static HarmonyMethod Merge(List attributes) { var result = new HarmonyMethod(); - if (attributes is null) return result; + if (attributes is null || attributes.Count == 0) return result; var resultTrv = Traverse.Create(result); attributes.ForEach(attribute => { diff --git a/Harmony/Public/Patch.cs b/Harmony/Public/Patch.cs index 0bb64ed0..ce37e36c 100644 --- a/Harmony/Public/Patch.cs +++ b/Harmony/Public/Patch.cs @@ -17,6 +17,7 @@ namespace HarmonyLib internal static class PatchInfoSerialization { #if NET5_0_OR_GREATER + static readonly JsonSerializerOptions serializerOptions = new() { IncludeFields = true }; internal static bool? useBinaryFormatter = null; internal static bool UseBinaryFormatter { @@ -98,8 +99,7 @@ internal static PatchInfo Deserialize(byte[] bytes) } else { - var options = new JsonSerializerOptions { IncludeFields = true }; - return JsonSerializer.Deserialize(bytes, options); + return JsonSerializer.Deserialize(bytes, serializerOptions); } #endif } @@ -283,13 +283,15 @@ private static Patch[] Add(string owner, HarmonyMethod[] add, Patch[] current) // concat lists var initialIndex = current.Length; - return current - .Concat( - add - .Where(method => method != null) - .Select((method, i) => new Patch(method, i + initialIndex, owner)) - ) - .ToArray(); + return + [ + .. current +, + .. add + .Where(method => method != null) + .Select((method, i) => new Patch(method, i + initialIndex, owner)) +, + ]; } /// Gets a list of patches with any from the given owner removed diff --git a/Harmony/Public/PatchClassProcessor.cs b/Harmony/Public/PatchClassProcessor.cs index 2c08008f..7f25825f 100644 --- a/Harmony/Public/PatchClassProcessor.cs +++ b/Harmony/Public/PatchClassProcessor.cs @@ -187,10 +187,10 @@ void ProcessPatchJob(PatchJobs.Job job) { var patchInfo = HarmonySharedState.GetPatchInfo(job.original) ?? new PatchInfo(); - patchInfo.AddPrefixes(instance.Id, job.prefixes.ToArray()); - patchInfo.AddPostfixes(instance.Id, job.postfixes.ToArray()); - patchInfo.AddTranspilers(instance.Id, job.transpilers.ToArray()); - patchInfo.AddFinalizers(instance.Id, job.finalizers.ToArray()); + patchInfo.AddPrefixes(instance.Id, [.. job.prefixes]); + patchInfo.AddPostfixes(instance.Id, [.. job.postfixes]); + patchInfo.AddTranspilers(instance.Id, [.. job.transpilers]); + patchInfo.AddFinalizers(instance.Id, [.. job.finalizers]); replacement = PatchFunctions.UpdateWrapper(job.original, patchInfo); HarmonySharedState.UpdatePatchInfo(job.original, replacement, patchInfo); diff --git a/Harmony/Public/PatchJsonConverter.cs b/Harmony/Public/PatchJsonConverter.cs index 98ba45d6..b35abf02 100644 --- a/Harmony/Public/PatchJsonConverter.cs +++ b/Harmony/Public/PatchJsonConverter.cs @@ -51,7 +51,7 @@ public override Patch Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSe // we shall not read end object here //_ = reader.Read(); - return new Patch(index, owner, priority, before.ToArray(), after.ToArray(), debug, methodToken, moduleGUID); + return new Patch(index, owner, priority, [.. before], [.. after], debug, methodToken, moduleGUID); } public override void Write(Utf8JsonWriter writer, Patch patchValue, JsonSerializerOptions options) diff --git a/Harmony/Public/PatchProcessor.cs b/Harmony/Public/PatchProcessor.cs index 5070d246..f86ce86f 100644 --- a/Harmony/Public/PatchProcessor.cs +++ b/Harmony/Public/PatchProcessor.cs @@ -9,10 +9,14 @@ namespace HarmonyLib { /// A PatchProcessor handles patches on a method/constructor /// - public class PatchProcessor + /// Creates an empty patch processor + /// The Harmony instance + /// The original method/constructor + /// + public class PatchProcessor(Harmony instance, MethodBase original) { - readonly Harmony instance; - readonly MethodBase original; + readonly Harmony instance = instance; + readonly MethodBase original = original; HarmonyMethod prefix; HarmonyMethod postfix; @@ -21,16 +25,6 @@ public class PatchProcessor internal static readonly object locker = new(); - /// Creates an empty patch processor - /// The Harmony instance - /// The original method/constructor - /// - public PatchProcessor(Harmony instance, MethodBase original) - { - this.instance = instance; - this.original = original; - } - /// Adds a prefix /// The prefix as a /// A for chaining calls @@ -266,7 +260,7 @@ public static ILGenerator CreateILGenerator(MethodBase original) var returnType = original is MethodInfo m ? m.ReturnType : typeof(void); var parameterTypes = original.GetParameters().Select(pi => pi.ParameterType).ToList(); if (original.IsStatic is false) parameterTypes.Insert(0, original.DeclaringType); - var method = new DynamicMethodDefinition($"ILGenerator_{original.Name}", returnType, parameterTypes.ToArray()); + var method = new DynamicMethodDefinition($"ILGenerator_{original.Name}", returnType, [.. parameterTypes]); return method.GetILGenerator(); } diff --git a/Harmony/Public/ReversePatcher.cs b/Harmony/Public/ReversePatcher.cs index 85d63dfb..4ddc6fe3 100644 --- a/Harmony/Public/ReversePatcher.cs +++ b/Harmony/Public/ReversePatcher.cs @@ -7,23 +7,16 @@ namespace HarmonyLib { /// A reverse patcher /// - public class ReversePatcher + /// Creates a reverse patcher + /// The Harmony instance + /// The original method/constructor + /// Your stand-in stub method as + /// + public class ReversePatcher(Harmony instance, MethodBase original, HarmonyMethod standin) { - readonly Harmony instance; - readonly MethodBase original; - readonly HarmonyMethod standin; - - /// Creates a reverse patcher - /// The Harmony instance - /// The original method/constructor - /// Your stand-in stub method as - /// - public ReversePatcher(Harmony instance, MethodBase original, HarmonyMethod standin) - { - this.instance = instance; - this.original = original; - this.standin = standin; - } + readonly Harmony instance = instance; + readonly MethodBase original = original; + readonly HarmonyMethod standin = standin; /// Applies the patch /// The type of patch, see diff --git a/Harmony/Tools/AccessTools.cs b/Harmony/Tools/AccessTools.cs index 679ed3ac..d09be2bb 100644 --- a/Harmony/Tools/AccessTools.cs +++ b/Harmony/Tools/AccessTools.cs @@ -40,7 +40,7 @@ public static class AccessTools /// Shortcut for to simplify the use of reflections and make it work for any access level but only within the current type /// - public static readonly BindingFlags allDeclared = all | BindingFlags.DeclaredOnly; // This should a be const, but changing from static (readonly) to const breaks binary compatibility. + public static readonly BindingFlags allDeclared = all | BindingFlags.DeclaredOnly; // This should a be const, but changing from static (readonly) to const breaks binary compatibility. /// Enumerates all assemblies in the current app domain, excluding visual studio assemblies /// An enumeration of @@ -279,7 +279,7 @@ public static PropertyInfo DeclaredIndexer(Type type, Type[] parameters = null) { // Can find multiple indexers without specified parameters, but only one with specified ones var indexer = parameters is null ? - type.GetProperties(allDeclared).SingleOrDefault(property => property.GetIndexParameters().Any()) + type.GetProperties(allDeclared).SingleOrDefault(property => property.GetIndexParameters().Length > 0) : type.GetProperties(allDeclared).FirstOrDefault(property => property.GetIndexParameters().Select(param => param.ParameterType).SequenceEqual(parameters)); if (indexer is null) FileLog.Debug($"AccessTools.DeclaredIndexer: Could not find indexer for type {type} and parameters {parameters?.Description()}"); @@ -399,7 +399,7 @@ public static PropertyInfo Indexer(Type type, Type[] parameters = null) // Can find multiple indexers without specified parameters, but only one with specified ones Func func = parameters is null ? - t => t.GetProperties(all).SingleOrDefault(property => property.GetIndexParameters().Any()) + t => t.GetProperties(all).SingleOrDefault(property => property.GetIndexParameters().Length > 0) : t => t.GetProperties(all).FirstOrDefault(property => property.GetIndexParameters().Select(param => param.ParameterType).SequenceEqual(parameters)); try @@ -843,7 +843,7 @@ public static List GetDeclaredMethods(Type type) FileLog.Debug("AccessTools.GetDeclaredMethods: type is null"); return []; } - return type.GetMethods(allDeclared).ToList(); + return [.. type.GetMethods(allDeclared)]; } /// Gets reflection information for all declared properties @@ -857,7 +857,7 @@ public static List GetDeclaredProperties(Type type) FileLog.Debug("AccessTools.GetDeclaredProperties: type is null"); return []; } - return type.GetProperties(allDeclared).ToList(); + return [.. type.GetProperties(allDeclared)]; } /// Gets reflection information for all declared fields @@ -871,7 +871,7 @@ public static List GetDeclaredFields(Type type) FileLog.Debug("AccessTools.GetDeclaredFields: type is null"); return []; } - return type.GetFields(allDeclared).ToList(); + return [.. type.GetFields(allDeclared)]; } /// Gets the return type of a method or constructor @@ -1832,8 +1832,8 @@ public static void RethrowException(Exception exception) /// public static void ThrowMissingMemberException(Type type, params string[] names) { - var fields = string.Join(",", GetFieldNames(type).ToArray()); - var properties = string.Join(",", GetPropertyNames(type).ToArray()); + var fields = string.Join(",", [.. GetFieldNames(type)]); + var properties = string.Join(",", [.. GetPropertyNames(type)]); throw new MissingMemberException($"{string.Join(",", names)}; available fields: {fields}; available properties: {properties}"); } diff --git a/HarmonyTests/IL/DynamicArgumentPatches.cs b/HarmonyTests/IL/DynamicArgumentPatches.cs index aca933fb..b301b5b6 100644 --- a/HarmonyTests/IL/DynamicArgumentPatches.cs +++ b/HarmonyTests/IL/DynamicArgumentPatches.cs @@ -212,7 +212,7 @@ public void Test_SendingArguments() TestMethods1.Test1(out var s); _ = new TestMethods2().Test2(123, "hello"); - _ = TestMethods3.Test3(new Vec3(2, 4, 6), new[] { 100, 200, 300 }.ToList()); + _ = TestMethods3.Test3(new Vec3(2, 4, 6), [100, 200, 300]); var n = 0; Assert.AreEqual(11, log.Count); diff --git a/HarmonyTests/Patching/Assets/PatchClasses.cs b/HarmonyTests/Patching/Assets/PatchClasses.cs index 145ca7cf..3c4ee52f 100644 --- a/HarmonyTests/Patching/Assets/PatchClasses.cs +++ b/HarmonyTests/Patching/Assets/PatchClasses.cs @@ -1447,7 +1447,7 @@ public static int Method2(Exception exception) var result = 0; try { - if (exception is object) + if (exception is not null) throw exception; } catch (Exception e) when (e.Message == "test") diff --git a/HarmonyTests/Patching/InternalPatches.cs b/HarmonyTests/Patching/InternalPatches.cs index 6c5eb429..25a32780 100644 --- a/HarmonyTests/Patching/InternalPatches.cs +++ b/HarmonyTests/Patching/InternalPatches.cs @@ -40,7 +40,7 @@ public void Test_Global_This_Assembly_Correct_GetExecutingAssembly() var assemblyOriginal = Assembly.GetExecutingAssembly(); var instance = new Harmony("test"); - instance.Patch(SymbolExtensions.GetMethodInfo((Assembly x) => Method(ref x)), + _ = instance.Patch(SymbolExtensions.GetMethodInfo((Assembly x) => Method(ref x)), prefix: SymbolExtensions.GetMethodInfo((Assembly x) => Prefix(ref x)), postfix: SymbolExtensions.GetMethodInfo((Assembly x) => Postfix(ref x)), transpiler: SymbolExtensions.GetMethodInfo(() => EmptyTranspiler(null)), @@ -57,7 +57,7 @@ public void Test_This_Assembly_Correct_GetExecutingAssembly() var assemblyOriginal = Assembly.GetExecutingAssembly(); var instance = new Harmony("test"); - instance.Patch(SymbolExtensions.GetMethodInfo((Assembly x) => Method(ref x)), + _ = instance.Patch(SymbolExtensions.GetMethodInfo((Assembly x) => Method(ref x)), prefix: SymbolExtensions.GetMethodInfo((Assembly x) => Prefix(ref x)), postfix: SymbolExtensions.GetMethodInfo((Assembly x) => Postfix(ref x)), transpiler: SymbolExtensions.GetMethodInfo(() => EmptyTranspiler(null)) diff --git a/TestLibrary/TestPatch.cs b/TestLibrary/TestPatch.cs index dace79de..1bb5b9c4 100644 --- a/TestLibrary/TestPatch.cs +++ b/TestLibrary/TestPatch.cs @@ -34,7 +34,7 @@ public static void TestGlobalPatch(out Assembly original, out Assembly patched) original = Assembly.GetExecutingAssembly(); var instance = new Harmony("test"); - instance.Patch(SymbolExtensions.GetMethodInfo((Assembly x) => Method(ref x, ref x, ref x)), + _ = instance.Patch(SymbolExtensions.GetMethodInfo((Assembly x) => Method(ref x, ref x, ref x)), transpiler: SymbolExtensions.GetMethodInfo(() => EmptyTranspiler(null)) ); @@ -45,7 +45,7 @@ public static void TestGlobalPatch(out Assembly original, out Assembly patched) public static void TestPatching(out Assembly prefix, out Assembly original, out Assembly postfix) { var instance = new Harmony("test"); - instance.Patch(SymbolExtensions.GetMethodInfo((Assembly x) => Method(ref x, ref x, ref x)), + _ = instance.Patch(SymbolExtensions.GetMethodInfo((Assembly x) => Method(ref x, ref x, ref x)), prefix: SymbolExtensions.GetMethodInfo((Assembly x) => Prefix(ref x)), postfix: SymbolExtensions.GetMethodInfo((Assembly x) => Postfix(ref x)), transpiler: SymbolExtensions.GetMethodInfo(() => EmptyTranspiler(null)),