From ca21a760a84f0332866114ae290a1feaab599460 Mon Sep 17 00:00:00 2001 From: Andreas Pardeike Date: Mon, 19 Feb 2024 21:35:30 +0100 Subject: [PATCH] adds shortcuts for some API functions, cleans code and applies C#12 syntax upgrades --- .editorconfig | 8 +- Harmony/Documentation/GlobalSuppressions.cs | 1 + .../Documentation/examples/execution_with.cs | 8 +- .../examples/execution_without.cs | 8 +- .../examples/intro_annotations.cs | 5 +- .../examples/patching-edgecases.cs | 26 +- .../examples/patching-finalizer.cs | 10 +- .../examples/patching-postfix.cs | 20 +- .../Documentation/examples/patching-prefix.cs | 12 +- .../examples/patching-transpiler.cs | 2 +- Harmony/Documentation/examples/priorities.cs | 20 +- .../examples/reverse-patching.cs | 8 +- Harmony/Documentation/examples/utilities.cs | 15 +- Harmony/Extras/FastAccess.cs | 12 +- Harmony/Extras/MethodInvoker.cs | 15 +- Harmony/GlobalSuppressions.cs | 4 + Harmony/Internal/ByteBuffer.cs | 5 +- Harmony/Internal/CodeTranspiler.cs | 10 +- Harmony/Internal/Emitter.cs | 30 +- Harmony/Internal/HarmonySharedState.cs | 3 +- Harmony/Internal/MethodCopier.cs | 32 +- Harmony/Internal/MethodPatcher.cs | 2 +- Harmony/Internal/PatchFunctions.cs | 6 +- Harmony/Internal/PatchModels.cs | 5 +- Harmony/Internal/PatchSorter.cs | 15 +- Harmony/Internal/PatchTools.cs | 5 +- Harmony/Public/Attributes.cs | 95 +---- Harmony/Public/CodeInstruction.cs | 20 +- Harmony/Public/Harmony.cs | 41 +- Harmony/Public/HarmonyException.cs | 20 +- Harmony/Public/HarmonyMethod.cs | 20 +- Harmony/Public/InlineSignature.cs | 10 +- Harmony/Public/Patch.cs | 93 ++--- Harmony/Public/PatchClassProcessor.cs | 4 +- Harmony/Public/PatchProcessor.cs | 17 +- Harmony/Public/Patches.cs | 8 +- Harmony/Tools/AccessTools.cs | 126 ++---- Harmony/Tools/Code.cs | 6 + Harmony/Tools/CodeMatch.cs | 132 +++++-- Harmony/Tools/CodeMatcher.cs | 105 ++--- Harmony/Tools/Extensions.cs | 78 +--- Harmony/Tools/FileLog.cs | 5 +- Harmony/Tools/SymbolExtensions.cs | 15 +- Harmony/Tools/Tools.cs | 6 +- Harmony/Tools/Traverse.cs | 65 +--- .../Extras/Assets/MethodInvokerClasses.cs | 5 +- HarmonyTests/Extras/PatchSerialization.cs | 4 +- HarmonyTests/GlobalSuppressions.cs | 16 +- HarmonyTests/IL/DynamicArgumentPatches.cs | 20 +- HarmonyTests/IL/TestMethodBodyReader.cs | 5 +- HarmonyTests/Patching/Arguments.cs | 2 +- HarmonyTests/Patching/Assets/ArgumentCases.cs | 85 +---- .../Patching/Assets/CombinedPatchClass.cs | 10 +- .../Patching/Assets/FinalizerPatchClasses.cs | 25 +- HarmonyTests/Patching/Assets/PatchClasses.cs | 360 ++++-------------- HarmonyTests/Patching/Assets/Specials.cs | 80 +--- HarmonyTests/Patching/FinalizerPatches.cs | 2 +- HarmonyTests/Patching/GenericsPatches.cs | 20 +- HarmonyTests/Patching/InternalPatches.cs | 5 +- HarmonyTests/Patching/PatchSorting.cs | 120 +++--- .../ReversePatching/Assets/ReversePatches.cs | 20 +- HarmonyTests/TestEnvironment.cs | 15 +- HarmonyTests/TestTools.cs | 228 ++++++++--- HarmonyTests/Tools/Assets/AccessToolsClass.cs | 115 ++---- HarmonyTests/Tools/TestAccessTools.cs | 5 +- HarmonyTests/Tools/TestFieldRefAccess.cs | 104 ++--- HarmonyTests/Tools/TestGettingInstructions.cs | 5 +- .../Assets/TraverseFields_AccessModifiers.cs | 23 +- .../Traverse/Assets/TraverseMethods.cs | 45 +-- .../TraverseProperties_AccessModifiers.cs | 16 +- HarmonyTests/Traverse/Assets/TraverseTypes.cs | 10 +- HarmonyTests/Traverse/TestTraverse_Basics.cs | 2 +- TestLibrary/TestPatch.cs | 12 +- 73 files changed, 819 insertions(+), 1693 deletions(-) diff --git a/.editorconfig b/.editorconfig index 6967d7e7..480efd97 100644 --- a/.editorconfig +++ b/.editorconfig @@ -37,9 +37,9 @@ dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggesti csharp_style_var_for_built_in_types = true:suggestion csharp_style_var_when_type_is_apparent = true:suggestion csharp_style_var_elsewhere = true:suggestion -csharp_style_expression_bodied_methods = false:suggestion -csharp_style_expression_bodied_constructors = false:suggestion -csharp_style_expression_bodied_operators = false:suggestion +csharp_style_expression_bodied_methods = when_on_single_line:suggestion +csharp_style_expression_bodied_constructors = when_on_single_line:suggestion +csharp_style_expression_bodied_operators = when_on_single_line:suggestion csharp_style_expression_bodied_properties = true:suggestion csharp_style_expression_bodied_indexers = true:suggestion csharp_style_expression_bodied_accessors = true:suggestion @@ -78,6 +78,7 @@ csharp_style_prefer_method_group_conversion = true:silent csharp_style_prefer_top_level_statements = true:silent csharp_style_expression_bodied_lambdas = when_on_single_line:silent csharp_style_expression_bodied_local_functions = when_on_single_line:silent +csharp_style_prefer_primary_constructors = true:suggestion [*.{cs,vb}] #### Naming styles #### @@ -141,3 +142,4 @@ dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion dotnet_style_operator_placement_when_wrapping = beginning_of_line tab_width = 3 indent_size = 3 +dotnet_style_allow_statement_immediately_after_block_experimental = true:silent diff --git a/Harmony/Documentation/GlobalSuppressions.cs b/Harmony/Documentation/GlobalSuppressions.cs index d023e715..35b3f4e0 100644 --- a/Harmony/Documentation/GlobalSuppressions.cs +++ b/Harmony/Documentation/GlobalSuppressions.cs @@ -17,6 +17,7 @@ [assembly: SuppressMessage("Performance", "CA1822")] [assembly: SuppressMessage("Performance", "CA1806")] +[assembly: SuppressMessage("Performance", "CA1859")] [assembly: SuppressMessage("", "CS0649")] [assembly: SuppressMessage("", "IDE0251")] diff --git a/Harmony/Documentation/examples/execution_with.cs b/Harmony/Documentation/examples/execution_with.cs index ba1e6f9c..ab89a36f 100644 --- a/Harmony/Documentation/examples/execution_with.cs +++ b/Harmony/Documentation/examples/execution_with.cs @@ -2,6 +2,7 @@ namespace Execution_With { using System; +#pragma warning disable CS9113 public class Code { // @@ -69,13 +70,14 @@ static R ReplacementMethod(T optionalThisArgument /*, ... arguments ... */ ) } // given the following signatures: - public static R Original() { return new R("original"); } + public static R Original() => new("original"); public static void SimpleFinalizer(ref R result) { } - public static Exception EditFinalizer(Exception ex, ref R result) { return ex; } + public static Exception EditFinalizer(Exception ex, ref R result) => ex; // - public class R { public R(string s) { } } + public class R(string s) { } public class T { } public static bool allVoid; } +#pragma warning restore CS9113 } diff --git a/Harmony/Documentation/examples/execution_without.cs b/Harmony/Documentation/examples/execution_without.cs index 51cb3108..6b00efc5 100644 --- a/Harmony/Documentation/examples/execution_without.cs +++ b/Harmony/Documentation/examples/execution_without.cs @@ -47,13 +47,13 @@ class R { } static int someArgument; static void SimplePrefix1(params object[] arguments) { } - static bool Prefix2() { return true; } + static bool Prefix2() => true; static void SimplePrefix3(params object[] arguments) { } static void SimplePrefix4(params object[] arguments) { } - static bool Prefix5(ref int i, ref R r) { return true; } - static R ModifiedOriginal(params object[] arguments) { return null; } + static bool Prefix5(ref int i, ref R r) => true; + static R ModifiedOriginal(params object[] arguments) => null; static void Postfix1(ref R r) { } - static R Postfix2(R r, params object[] arguments) { return r; } + static R Postfix2(R r, params object[] arguments) => r; static void Postfix3() { } } } diff --git a/Harmony/Documentation/examples/intro_annotations.cs b/Harmony/Documentation/examples/intro_annotations.cs index c1ca43ad..4fdbe9a6 100644 --- a/Harmony/Documentation/examples/intro_annotations.cs +++ b/Harmony/Documentation/examples/intro_annotations.cs @@ -36,10 +36,7 @@ static bool Prefix(SomeGameClass __instance, ref int ___counter) return true; } - static void Postfix(ref int __result) - { - __result *= 2; - } + static void Postfix(ref int __result) => __result *= 2; } // } diff --git a/Harmony/Documentation/examples/patching-edgecases.cs b/Harmony/Documentation/examples/patching-edgecases.cs index 5f7b02ac..97ac5206 100644 --- a/Harmony/Documentation/examples/patching-edgecases.cs +++ b/Harmony/Documentation/examples/patching-edgecases.cs @@ -11,7 +11,7 @@ class Patch [HarmonyReversePatch] [HarmonyPatch(typeof(BaseClass), nameof(BaseClass.Method))] [MethodImpl(MethodImplOptions.NoInlining)] - static string BaseMethodDummy(SubClass instance) { return null; } + static string BaseMethodDummy(SubClass instance) => null; [HarmonyPatch(typeof(SubClass), nameof(SubClass.Method))] static void Prefix(SubClass __instance) @@ -23,18 +23,12 @@ static void Prefix(SubClass __instance) public class BaseClass { - public virtual string Method() - { - return "base"; - } + public virtual string Method() => "base"; } public class SubClass : BaseClass { - public override string Method() - { - return "subclass"; - } + public override string Method() => "subclass"; } // @@ -67,15 +61,9 @@ class SomeGameObject { GameObject gameObject; - void SomeMethod() - { - UnityEngine.Object.DontDestroyOnLoad(gameObject); - } + void SomeMethod() => UnityEngine.Object.DontDestroyOnLoad(gameObject); - void SomeOtherMethod() - { - SomeMethod(); - } + void SomeOtherMethod() => SomeMethod(); } // #pragma warning restore CS0649 @@ -85,11 +73,9 @@ public static class Patcher { private static bool patched = false; - public static void Main() - { + public static void Main() => //DoPatch(); <-- Do not execute patching on assembly entry point SceneManager.sceneLoaded += SceneLoaded; - } private static void DoPatch() { diff --git a/Harmony/Documentation/examples/patching-finalizer.cs b/Harmony/Documentation/examples/patching-finalizer.cs index 1babf68e..11f90d53 100644 --- a/Harmony/Documentation/examples/patching-finalizer.cs +++ b/Harmony/Documentation/examples/patching-finalizer.cs @@ -15,16 +15,10 @@ public class MyException : Exception public MyException() { } public MyException(string message) : base(message) { } public MyException(string message, Exception innerException) : base(message, innerException) { } - protected MyException(SerializationInfo serializationInfo, StreamingContext streamingContext) - { - throw new NotImplementedException(); - } + protected MyException(SerializationInfo serializationInfo, StreamingContext streamingContext) => throw new NotImplementedException(); } - static Exception Finalizer(Exception __exception) - { - return new MyException("Oops", __exception); - } + static Exception Finalizer(Exception __exception) => new MyException("Oops", __exception); // } } diff --git a/Harmony/Documentation/examples/patching-postfix.cs b/Harmony/Documentation/examples/patching-postfix.cs index d2faafdc..6f965ef4 100644 --- a/Harmony/Documentation/examples/patching-postfix.cs +++ b/Harmony/Documentation/examples/patching-postfix.cs @@ -8,10 +8,7 @@ public class ResultExample // public class OriginalCode { - public string GetName() - { - return name; // ... - } + public string GetName() => name; // ... } [HarmonyPatch(typeof(OriginalCode), nameof(OriginalCode.GetName))] @@ -33,10 +30,7 @@ public class PassThroughExample // public class OriginalCode { - public string GetName() - { - return "David"; - } + public string GetName() => "David"; public IEnumerable GetNumbers() { @@ -49,10 +43,7 @@ public IEnumerable GetNumbers() [HarmonyPatch(typeof(OriginalCode), nameof(OriginalCode.GetName))] class Patch1 { - static string Postfix(string name) - { - return "Hello " + name; - } + static string Postfix(string name) => "Hello " + name; } [HarmonyPatch(typeof(OriginalCode), nameof(OriginalCode.GetNumbers))] @@ -86,10 +77,7 @@ public void Test(int counter) [HarmonyPatch(typeof(OriginalCode), nameof(OriginalCode.Test))] class Patch { - static void Prefix(int counter) - { - FileLog.Log("counter = " + counter); - } + static void Prefix(int counter) => FileLog.Log("counter = " + counter); } // } diff --git a/Harmony/Documentation/examples/patching-prefix.cs b/Harmony/Documentation/examples/patching-prefix.cs index 2c284c48..8ef41af6 100644 --- a/Harmony/Documentation/examples/patching-prefix.cs +++ b/Harmony/Documentation/examples/patching-prefix.cs @@ -31,10 +31,7 @@ public class SkipExample // public class OriginalCode { - public string GetName() - { - return name; // ... - } + public string GetName() => name; // ... } [HarmonyPatch(typeof(OriginalCode), nameof(OriginalCode.GetName))] @@ -56,10 +53,7 @@ public class SkipMaybeExample // public class OriginalCode { - public bool IsFullAfterTakingIn(int i) - { - return DoSomeExpensiveCalculation() > i; - } + public bool IsFullAfterTakingIn(int i) => DoSomeExpensiveCalculation() > i; } [HarmonyPatch(typeof(OriginalCode), nameof(OriginalCode.IsFullAfterTakingIn))] @@ -77,7 +71,7 @@ static bool Prefix(ref bool __result, int i) } // - static int DoSomeExpensiveCalculation() { return 0; } + static int DoSomeExpensiveCalculation() => 0; } public class StateExample diff --git a/Harmony/Documentation/examples/patching-transpiler.cs b/Harmony/Documentation/examples/patching-transpiler.cs index fd9d8933..a4a337a3 100644 --- a/Harmony/Documentation/examples/patching-transpiler.cs +++ b/Harmony/Documentation/examples/patching-transpiler.cs @@ -36,7 +36,7 @@ class SomeType { public string someField; } class Tools { - public static MethodInfo MyExtraMethod() { return null; } + public static MethodInfo MyExtraMethod() => null; } static void ReportError(string s) { } diff --git a/Harmony/Documentation/examples/priorities.cs b/Harmony/Documentation/examples/priorities.cs index 04ba6bf8..a4595152 100644 --- a/Harmony/Documentation/examples/priorities.cs +++ b/Harmony/Documentation/examples/priorities.cs @@ -6,10 +6,7 @@ namespace Priorities // class Foo { - static string Bar() - { - return "secret"; - } + static string Bar() => "secret"; } // @@ -26,10 +23,7 @@ void Main_Plugin1() [HarmonyPatch("Bar")] class MyPatch { - static void Postfix(ref string result) - { - result = "new secret 1"; - } + static void Postfix(ref string result) => result = "new secret 1"; } // } @@ -48,10 +42,7 @@ void Main_Plugin1b() class MyPatch { [HarmonyAfter(["net.example.plugin2"])] - static void Postfix(ref string result) - { - result = "new secret 1"; - } + static void Postfix(ref string result) => result = "new secret 1"; } // } @@ -69,10 +60,7 @@ void Main_Plugin2() [HarmonyPatch("Bar")] class MyPatch { - static void Postfix(ref string result) - { - result = "new secret 2"; - } + static void Postfix(ref string result) => result = "new secret 2"; } // } diff --git a/Harmony/Documentation/examples/reverse-patching.cs b/Harmony/Documentation/examples/reverse-patching.cs index 9464eec6..bff2073d 100644 --- a/Harmony/Documentation/examples/reverse-patching.cs +++ b/Harmony/Documentation/examples/reverse-patching.cs @@ -23,20 +23,16 @@ public class Patch { [HarmonyReversePatch] [HarmonyPatch(typeof(OriginalCode), "Test")] - public static void MyTest(object instance, int counter, string name) - { + public static void MyTest(object instance, int counter, string name) => // its a stub so it has no initial content throw new NotImplementedException("It's a stub"); - } } class Main { - void Test() - { + void Test() => // here we call OriginalCode.Test() Patch.MyTest(originalInstance, 100, "hello"); - } } // diff --git a/Harmony/Documentation/examples/utilities.cs b/Harmony/Documentation/examples/utilities.cs index 2bfb5653..129059b4 100644 --- a/Harmony/Documentation/examples/utilities.cs +++ b/Harmony/Documentation/examples/utilities.cs @@ -12,10 +12,7 @@ struct Bar { static string secret = "hello"; - public string ModifiedSecret() - { - return secret.ToUpper(); - } + public string ModifiedSecret() => secret.ToUpper(); } Bar MyBar @@ -26,19 +23,13 @@ Bar MyBar } } - public string GetSecret() - { - return MyBar.ModifiedSecret(); - } + public string GetSecret() => MyBar.ModifiedSecret(); Foo() { } - static Foo MakeFoo() - { - return new Foo(); - } + static Foo MakeFoo() => new(); } void Test() diff --git a/Harmony/Extras/FastAccess.cs b/Harmony/Extras/FastAccess.cs index 4af91d53..e58d4bb3 100644 --- a/Harmony/Extras/FastAccess.cs +++ b/Harmony/Extras/FastAccess.cs @@ -43,7 +43,7 @@ public static InstantiationHandler CreateInstantiationHandler() { var constructorInfo = typeof(T).GetConstructor(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance, null, - new Type[0], null); + [], null); if (constructorInfo is null) { throw new ApplicationException(string.Format( @@ -162,14 +162,8 @@ public static SetterHandler CreateSetterHandler(FieldInfo fieldInfo) return (SetterHandler)dynamicSet.Generate().CreateDelegate(typeof(SetterHandler)); } - static DynamicMethodDefinition CreateGetDynamicMethod(Type type) - { - return new DynamicMethodDefinition($"DynamicGet_{type.Name}", typeof(S), [typeof(T)]); - } + static DynamicMethodDefinition CreateGetDynamicMethod(Type type) => new($"DynamicGet_{type.Name}", typeof(S), [typeof(T)]); - static DynamicMethodDefinition CreateSetDynamicMethod(Type type) - { - return new DynamicMethodDefinition($"DynamicSet_{type.Name}", typeof(void), [typeof(T), typeof(S)]); - } + static DynamicMethodDefinition CreateSetDynamicMethod(Type type) => new($"DynamicSet_{type.Name}", typeof(void), [typeof(T), typeof(S)]); } } diff --git a/Harmony/Extras/MethodInvoker.cs b/Harmony/Extras/MethodInvoker.cs index 930a28f5..e1fbc2c4 100644 --- a/Harmony/Extras/MethodInvoker.cs +++ b/Harmony/Extras/MethodInvoker.cs @@ -144,20 +144,11 @@ public static FastInvokeHandler GetHandler(MethodInfo methodInfo, bool directBox return invoder; } - internal static void Emit(ILGenerator il, OpCode opcode) - { - il.Emit(opcode); - } + internal static void Emit(ILGenerator il, OpCode opcode) => il.Emit(opcode); - internal static void Emit(ILGenerator il, OpCode opcode, Type type) - { - il.Emit(opcode, type); - } + internal static void Emit(ILGenerator il, OpCode opcode, Type type) => il.Emit(opcode, type); - internal static void EmitCall(ILGenerator il, OpCode opcode, MethodInfo methodInfo) - { - il.EmitCall(opcode, methodInfo, null); - } + internal static void EmitCall(ILGenerator il, OpCode opcode, MethodInfo methodInfo) => il.EmitCall(opcode, methodInfo, null); static void EmitUnboxIfNeeded(ILGenerator il, Type type) { diff --git a/Harmony/GlobalSuppressions.cs b/Harmony/GlobalSuppressions.cs index 847e4bec..bc560d54 100644 --- a/Harmony/GlobalSuppressions.cs +++ b/Harmony/GlobalSuppressions.cs @@ -19,3 +19,7 @@ [assembly: SuppressMessage("Reliability", "CA2020:Prevent from behavioral change", Justification = "", Scope = "member", Target = "~M:HarmonyLib.FileLog.LogBytes(System.Int64,System.Int32)")] [assembly: SuppressMessage("Performance", "CA1850:Prefer static 'HashData' method over 'ComputeHash'", Justification = "", Scope = "member", Target = "~M:HarmonyLib.FileLog.LogBytes(System.Int64,System.Int32)")] + +#if NET8_0_OR_GREATER +[assembly: SuppressMessage("Maintainability", "CA1510")] +#endif diff --git a/Harmony/Internal/ByteBuffer.cs b/Harmony/Internal/ByteBuffer.cs index 99e81ce9..26176089 100644 --- a/Harmony/Internal/ByteBuffer.cs +++ b/Harmony/Internal/ByteBuffer.cs @@ -8,10 +8,7 @@ internal class ByteBuffer internal int position; - internal ByteBuffer(byte[] buffer) - { - this.buffer = buffer; - } + internal ByteBuffer(byte[] buffer) => this.buffer = buffer; internal byte ReadByte() { diff --git a/Harmony/Internal/CodeTranspiler.cs b/Harmony/Internal/CodeTranspiler.cs index 3bfc240b..778e8796 100644 --- a/Harmony/Internal/CodeTranspiler.cs +++ b/Harmony/Internal/CodeTranspiler.cs @@ -19,10 +19,7 @@ internal CodeTranspiler(List ilInstructions) .ToList().AsEnumerable(); } - internal void Add(MethodInfo transpiler) - { - transpilers.Add(transpiler); - } + internal void Add(MethodInfo transpiler) => transpilers.Add(transpiler); internal static object ConvertInstruction(Type type, object instruction, out Dictionary unassigned) { @@ -191,10 +188,7 @@ internal static IEnumerable ConvertToOurInstructions(IEnumerable instructions, T } } - static bool IsCodeInstructionsParameter(Type type) - { - return type.IsGenericType && type.GetGenericTypeDefinition().Name.StartsWith("IEnumerable", StringComparison.Ordinal); - } + static bool IsCodeInstructionsParameter(Type type) => type.IsGenericType && type.GetGenericTypeDefinition().Name.StartsWith("IEnumerable", StringComparison.Ordinal); internal static IEnumerable ConvertToGeneralInstructions(MethodInfo transpiler, IEnumerable enumerable, out Dictionary> unassignedValues) { diff --git a/Harmony/Internal/Emitter.cs b/Harmony/Internal/Emitter.cs index a1794d2a..4d4c050d 100644 --- a/Harmony/Internal/Emitter.cs +++ b/Harmony/Internal/Emitter.cs @@ -10,10 +10,7 @@ namespace HarmonyLib { internal class LeaveTry { - public override string ToString() - { - return "(autogenerated)"; - } + public override string ToString() => "(autogenerated)"; } internal class Emitter @@ -28,30 +25,15 @@ internal Emitter(ILGenerator il, bool debug) this.debug = debug; } - internal Dictionary GetInstructions() - { - return instructions; - } + internal Dictionary GetInstructions() => instructions; - internal void AddInstruction(OpCode opcode, object operand) - { - instructions.Add(CurrentPos(), new CodeInstruction(opcode, operand)); - } + internal void AddInstruction(OpCode opcode, object operand) => instructions.Add(CurrentPos(), new CodeInstruction(opcode, operand)); - internal int CurrentPos() - { - return il.ILOffset; - } + internal int CurrentPos() => il.ILOffset; - internal static string CodePos(int offset) - { - return string.Format("IL_{0:X4}: ", offset); - } + internal static string CodePos(int offset) => string.Format("IL_{0:X4}: ", offset); - internal string CodePos() - { - return CodePos(CurrentPos()); - } + internal string CodePos() => CodePos(CurrentPos()); internal void LogComment(string comment) { diff --git a/Harmony/Internal/HarmonySharedState.cs b/Harmony/Internal/HarmonySharedState.cs index 4b145cd5..839dfa21 100644 --- a/Harmony/Internal/HarmonySharedState.cs +++ b/Harmony/Internal/HarmonySharedState.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; -using System.Linq; using System.Reflection; namespace HarmonyLib @@ -112,7 +111,7 @@ internal static PatchInfo GetPatchInfo(MethodBase method) internal static IEnumerable GetPatchedMethods() { - lock (state) return state.Keys.ToArray(); + lock (state) return [.. state.Keys]; } internal static void UpdatePatchInfo(MethodBase original, MethodInfo replacement, PatchInfo patchInfo) diff --git a/Harmony/Internal/MethodCopier.cs b/Harmony/Internal/MethodCopier.cs index 0f93b1c4..70f6b817 100644 --- a/Harmony/Internal/MethodCopier.cs +++ b/Harmony/Internal/MethodCopier.cs @@ -24,20 +24,11 @@ internal MethodCopier(MethodBase fromMethod, ILGenerator toILGenerator, LocalBui reader.GenerateInstructions(); } - internal void SetDebugging(bool debug) - { - reader.SetDebugging(debug); - } + internal void SetDebugging(bool debug) => reader.SetDebugging(debug); - internal void AddTranspiler(MethodInfo transpiler) - { - transpilers.Add(transpiler); - } + internal void AddTranspiler(MethodInfo transpiler) => transpilers.Add(transpiler); - internal List Finalize(Emitter emitter, List