From 16f00a1bb101f6c73f2e924632241424db1d197f Mon Sep 17 00:00:00 2001 From: Andreas Pardeike Date: Mon, 19 Feb 2024 22:57:34 +0100 Subject: [PATCH] reverts some [] syntax so it compiles in all .net versions --- Harmony/Internal/HarmonySharedState.cs | 6 +++++- Harmony/Public/PatchClassProcessor.cs | 7 +++++-- Harmony/Tools/CodeMatcher.cs | 8 ++++++-- Harmony/Tools/Extensions.cs | 4 +++- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Harmony/Internal/HarmonySharedState.cs b/Harmony/Internal/HarmonySharedState.cs index 839dfa21..170701f8 100644 --- a/Harmony/Internal/HarmonySharedState.cs +++ b/Harmony/Internal/HarmonySharedState.cs @@ -3,6 +3,8 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.Diagnostics.CodeAnalysis; +using System.Linq; using System.Reflection; namespace HarmonyLib @@ -109,9 +111,11 @@ internal static PatchInfo GetPatchInfo(MethodBase method) return PatchInfoSerialization.Deserialize(bytes); } + + [SuppressMessage("Style", "IDE0305")] internal static IEnumerable GetPatchedMethods() { - lock (state) return [.. state.Keys]; + lock (state) return state.Keys.ToArray(); } internal static void UpdatePatchInfo(MethodBase original, MethodInfo replacement, PatchInfo patchInfo) diff --git a/Harmony/Public/PatchClassProcessor.cs b/Harmony/Public/PatchClassProcessor.cs index 20a0e3e5..2f92a6d9 100644 --- a/Harmony/Public/PatchClassProcessor.cs +++ b/Harmony/Public/PatchClassProcessor.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Reflection; @@ -274,11 +275,12 @@ void ReportException(Exception exception, MethodBase original) throw new HarmonyException($"Patching exception in method {original.FullDescription()}", exception); } + [SuppressMessage("Style", "IDE0300")] T RunMethod(T defaultIfNotExisting, T defaultIfFailing, Func failOnResult = null, params object[] parameters) { if (auxilaryMethods.TryGetValue(typeof(S), out var method)) { - var input = (parameters ?? []).Union([instance]).ToArray(); + var input = (parameters ?? []).Union(new object[] { instance }).ToArray(); var actualParameters = AccessTools.ActualParameters(method, input); if (method.ReturnType != typeof(void) && typeof(T).IsAssignableFrom(method.ReturnType) is false) @@ -312,11 +314,12 @@ T RunMethod(T defaultIfNotExisting, T defaultIfFailing, Func fa return defaultIfNotExisting; } + [SuppressMessage("Style", "IDE0300")] void RunMethod(ref Exception exception, params object[] parameters) { if (auxilaryMethods.TryGetValue(typeof(S), out var method)) { - var input = (parameters ?? []).Union([instance]).ToArray(); + var input = (parameters ?? []).Union(new object[] { instance }).ToArray(); var actualParameters = AccessTools.ActualParameters(method, input); try { diff --git a/Harmony/Tools/CodeMatcher.cs b/Harmony/Tools/CodeMatcher.cs index 8d49ca6b..ca5e3429 100644 --- a/Harmony/Tools/CodeMatcher.cs +++ b/Harmony/Tools/CodeMatcher.cs @@ -3,6 +3,7 @@ using System.Linq; using System.Reflection; using System.Reflection.Emit; +using System.Diagnostics.CodeAnalysis; namespace HarmonyLib { @@ -344,10 +345,11 @@ public CodeMatcher CreateLabel(out Label label) /// [out] The new label /// The same code matcher /// + [SuppressMessage("Style", "IDE0300")] public CodeMatcher CreateLabelAt(int position, out Label label) { label = generator.DefineLabel(); - _ = AddLabelsAt(position, [label]); + _ = AddLabelsAt(position, new Label[] { label }); return this; } @@ -356,10 +358,12 @@ public CodeMatcher CreateLabelAt(int position, out Label label) /// [out] The new label /// The same code matcher /// + + [SuppressMessage("Style", "IDE0300")] public CodeMatcher CreateLabelWithOffsets(int offset, out Label label) { label = generator.DefineLabel(); - return AddLabelsAt(Pos + offset, [label]); + return AddLabelsAt(Pos + offset, new Label[] { label }); } /// Adds an enumeration of labels to current position diff --git a/Harmony/Tools/Extensions.cs b/Harmony/Tools/Extensions.cs index efe75f42..7562a638 100644 --- a/Harmony/Tools/Extensions.cs +++ b/Harmony/Tools/Extensions.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Reflection; using System.Reflection.Emit; @@ -670,7 +671,8 @@ public static void Do(this IEnumerable sequence, Action action) /// The item to add /// The collection containing the item /// - public static IEnumerable AddItem(this IEnumerable sequence, T item) => (sequence ?? []).Concat([item]); + [SuppressMessage("Style", "IDE0300")] + public static IEnumerable AddItem(this IEnumerable sequence, T item) => (sequence ?? []).Concat(new T[] { item }); /// A helper to add an item to an array /// The inner type of the collection