From 606ba09b5fb08b6d0408fcdd3190dfd518b9f79a Mon Sep 17 00:00:00 2001 From: Andreas Pardeike Date: Fri, 29 Dec 2023 15:53:30 +0100 Subject: [PATCH] code cleanup, net8.0, optional ret code for methods ending in throw --- Harmony/Documentation/Documentation.csproj | 2 +- Harmony/Harmony.csproj | 5 +- Harmony/Internal/AccessCache.cs | 18 +++---- Harmony/Internal/CodeTranspiler.cs | 4 +- Harmony/Internal/Emitter.cs | 2 +- Harmony/Internal/HarmonySharedState.cs | 2 +- Harmony/Internal/ILInstruction.cs | 4 +- Harmony/Internal/MethodCopier.cs | 6 +-- Harmony/Internal/MethodPatcher.cs | 3 +- Harmony/Internal/PatchModels.cs | 10 ++-- Harmony/Internal/PatchSorter.cs | 8 +-- Harmony/Internal/PatchTools.cs | 2 +- Harmony/Public/CodeInstruction.cs | 10 ++-- Harmony/Public/InlineSignature.cs | 2 +- Harmony/Public/PatchClassProcessor.cs | 22 ++++---- Harmony/Tools/AccessTools.cs | 31 ++++++----- Harmony/Tools/AccessToolsExtensions.cs | 4 +- Harmony/Tools/CodeMatch.cs | 8 +-- Harmony/Tools/CodeMatcher.cs | 6 +-- Harmony/Tools/Extensions.cs | 54 +++++++++---------- Harmony/Tools/FileLog.cs | 4 +- HarmonyTests/HarmonyTests.csproj | 4 +- HarmonyTests/IL/DynamicArgumentPatches.cs | 4 +- .../Patching/Assets/CombinedPatchClass.cs | 16 +++++- HarmonyTests/Patching/Assets/PatchClasses.cs | 18 +++---- HarmonyTests/Patching/Assets/Specials.cs | 8 +-- HarmonyTests/Patching/FinalizerPatches.cs | 2 +- HarmonyTests/Patching/GenericsPatches.cs | 6 +-- HarmonyTests/Patching/Transpiling.cs | 2 +- HarmonyTests/Tools/Assets/AccessToolsClass.cs | 2 +- HarmonyTests/Tools/TestFieldRefAccess.cs | 2 +- HarmonyTests/Traverse/TestTraverse_Basics.cs | 2 +- TestLibrary/TestLibrary.csproj | 2 +- TestLibrary/TestPatch.cs | 2 +- azure-pipelines.yml | 8 +-- testEnvironments.json | 10 ++++ 36 files changed, 163 insertions(+), 132 deletions(-) create mode 100644 testEnvironments.json diff --git a/Harmony/Documentation/Documentation.csproj b/Harmony/Documentation/Documentation.csproj index d1b1ac8b..584cff2c 100644 --- a/Harmony/Documentation/Documentation.csproj +++ b/Harmony/Documentation/Documentation.csproj @@ -1,7 +1,7 @@ - net35;net452;net472;net48;netcoreapp3.0;netcoreapp3.1;net5.0;net6.0;net7.0 + net35;net452;net472;net48;netcoreapp3.0;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0 preview false obj diff --git a/Harmony/Harmony.csproj b/Harmony/Harmony.csproj index 35e9b537..0daf6891 100644 --- a/Harmony/Harmony.csproj +++ b/Harmony/Harmony.csproj @@ -1,7 +1,7 @@ - netstandard2.0;net35;net452;net472;net48;netcoreapp3.0;netcoreapp3.1;net5.0;net6.0;net7.0 + netstandard2.0;net35;net452;net472;net48;netcoreapp3.0;netcoreapp3.1;net5.0;net6.0;net7.0;net8.0 true Harmony Andreas Pardeike @@ -35,7 +35,7 @@ - + true @@ -122,6 +122,7 @@ + diff --git a/Harmony/Internal/AccessCache.cs b/Harmony/Internal/AccessCache.cs index 89d922c7..ed8c4046 100644 --- a/Harmony/Internal/AccessCache.cs +++ b/Harmony/Internal/AccessCache.cs @@ -21,13 +21,13 @@ internal enum MemberType { MemberType.Static, BasicFlags | BindingFlags.Static } }; - readonly Dictionary> declaredFields = new(); - readonly Dictionary> declaredProperties = new(); - readonly Dictionary>> declaredMethods = new(); + readonly Dictionary> declaredFields = []; + readonly Dictionary> declaredProperties = []; + readonly Dictionary>> declaredMethods = []; - readonly Dictionary> inheritedFields = new(); - readonly Dictionary> inheritedProperties = new(); - readonly Dictionary>> inheritedMethods = new(); + readonly Dictionary> inheritedFields = []; + readonly Dictionary> inheritedProperties = []; + readonly Dictionary>> inheritedMethods = []; static T Get(Dictionary> dict, Type type, string name, Func fetcher) { @@ -35,7 +35,7 @@ static T Get(Dictionary> dict, Type type, string { if (dict.TryGetValue(type, out var valuesByName) is false) { - valuesByName = new Dictionary(); + valuesByName = []; dict[type] = valuesByName; } if (valuesByName.TryGetValue(name, out var value) is false) @@ -53,12 +53,12 @@ static T Get(Dictionary>> dict, T { if (dict.TryGetValue(type, out var valuesByName) is false) { - valuesByName = new Dictionary>(); + valuesByName = []; dict[type] = valuesByName; } if (valuesByName.TryGetValue(name, out var valuesByArgument) is false) { - valuesByArgument = new Dictionary(); + valuesByArgument = []; valuesByName[name] = valuesByArgument; } var argumentsHash = AccessTools.CombinedHashCode(arguments); diff --git a/Harmony/Internal/CodeTranspiler.cs b/Harmony/Internal/CodeTranspiler.cs index 14adb97e..31020c87 100644 --- a/Harmony/Internal/CodeTranspiler.cs +++ b/Harmony/Internal/CodeTranspiler.cs @@ -10,7 +10,7 @@ namespace HarmonyLib internal class CodeTranspiler { readonly IEnumerable codeInstructions; - readonly List transpilers = new(); + readonly List transpilers = []; internal CodeTranspiler(List ilInstructions) { @@ -156,7 +156,7 @@ internal static IEnumerable ConvertInstructionsAndUnassignedValues(Type type, IE var listType = enumerableAssembly.GetType(genericListTypeWithElement.FullName); var list = Activator.CreateInstance(listType); var listAdd = list.GetType().GetMethod("Add"); - unassignedValues = new Dictionary>(); + unassignedValues = []; foreach (var op in enumerable) { var elementTo = ConvertInstruction(elementType, op, out var unassigned); diff --git a/Harmony/Internal/Emitter.cs b/Harmony/Internal/Emitter.cs index 4221e2c9..a7357cd5 100644 --- a/Harmony/Internal/Emitter.cs +++ b/Harmony/Internal/Emitter.cs @@ -19,7 +19,7 @@ public override string ToString() internal class Emitter { readonly CecilILGenerator il; - readonly Dictionary instructions = new(); + readonly Dictionary instructions = []; readonly bool debug; internal Emitter(ILGenerator il, bool debug) diff --git a/Harmony/Internal/HarmonySharedState.cs b/Harmony/Internal/HarmonySharedState.cs index d632e764..4b145cd5 100644 --- a/Harmony/Internal/HarmonySharedState.cs +++ b/Harmony/Internal/HarmonySharedState.cs @@ -65,7 +65,7 @@ static HarmonySharedState() state = (Dictionary)stateField.GetValue(null); // copy 'originals' over to our fields - originals = new Dictionary(); + originals = []; if (originalsField != null) // may not exist in older versions originals = (Dictionary)originalsField.GetValue(null); } diff --git a/Harmony/Internal/ILInstruction.cs b/Harmony/Internal/ILInstruction.cs index 454aed2e..d84d9408 100644 --- a/Harmony/Internal/ILInstruction.cs +++ b/Harmony/Internal/ILInstruction.cs @@ -11,8 +11,8 @@ internal class ILInstruction internal object operand; internal object argument; - internal List