Skip to content

Commit 16f00a1

Browse files
committed
reverts some [] syntax so it compiles in all .net versions
1 parent 9615407 commit 16f00a1

File tree

4 files changed

+19
-6
lines changed

4 files changed

+19
-6
lines changed

Harmony/Internal/HarmonySharedState.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
using System;
44
using System.Collections.Generic;
55
using System.Diagnostics;
6+
using System.Diagnostics.CodeAnalysis;
7+
using System.Linq;
68
using System.Reflection;
79

810
namespace HarmonyLib
@@ -109,9 +111,11 @@ internal static PatchInfo GetPatchInfo(MethodBase method)
109111
return PatchInfoSerialization.Deserialize(bytes);
110112
}
111113

114+
115+
[SuppressMessage("Style", "IDE0305")]
112116
internal static IEnumerable<MethodBase> GetPatchedMethods()
113117
{
114-
lock (state) return [.. state.Keys];
118+
lock (state) return state.Keys.ToArray();
115119
}
116120

117121
internal static void UpdatePatchInfo(MethodBase original, MethodInfo replacement, PatchInfo patchInfo)

Harmony/Public/PatchClassProcessor.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics.CodeAnalysis;
34
using System.Linq;
45
using System.Reflection;
56

@@ -274,11 +275,12 @@ void ReportException(Exception exception, MethodBase original)
274275
throw new HarmonyException($"Patching exception in method {original.FullDescription()}", exception);
275276
}
276277

278+
[SuppressMessage("Style", "IDE0300")]
277279
T RunMethod<S, T>(T defaultIfNotExisting, T defaultIfFailing, Func<T, string> failOnResult = null, params object[] parameters)
278280
{
279281
if (auxilaryMethods.TryGetValue(typeof(S), out var method))
280282
{
281-
var input = (parameters ?? []).Union([instance]).ToArray();
283+
var input = (parameters ?? []).Union(new object[] { instance }).ToArray();
282284
var actualParameters = AccessTools.ActualParameters(method, input);
283285

284286
if (method.ReturnType != typeof(void) && typeof(T).IsAssignableFrom(method.ReturnType) is false)
@@ -312,11 +314,12 @@ T RunMethod<S, T>(T defaultIfNotExisting, T defaultIfFailing, Func<T, string> fa
312314
return defaultIfNotExisting;
313315
}
314316

317+
[SuppressMessage("Style", "IDE0300")]
315318
void RunMethod<S>(ref Exception exception, params object[] parameters)
316319
{
317320
if (auxilaryMethods.TryGetValue(typeof(S), out var method))
318321
{
319-
var input = (parameters ?? []).Union([instance]).ToArray();
322+
var input = (parameters ?? []).Union(new object[] { instance }).ToArray();
320323
var actualParameters = AccessTools.ActualParameters(method, input);
321324
try
322325
{

Harmony/Tools/CodeMatcher.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using System.Reflection;
55
using System.Reflection.Emit;
6+
using System.Diagnostics.CodeAnalysis;
67

78
namespace HarmonyLib
89
{
@@ -344,10 +345,11 @@ public CodeMatcher CreateLabel(out Label label)
344345
/// <param name="label">[out] The new label</param>
345346
/// <returns>The same code matcher</returns>
346347
///
348+
[SuppressMessage("Style", "IDE0300")]
347349
public CodeMatcher CreateLabelAt(int position, out Label label)
348350
{
349351
label = generator.DefineLabel();
350-
_ = AddLabelsAt(position, [label]);
352+
_ = AddLabelsAt(position, new Label[] { label });
351353
return this;
352354
}
353355

@@ -356,10 +358,12 @@ public CodeMatcher CreateLabelAt(int position, out Label label)
356358
/// <param name="label">[out] The new label</param>
357359
/// <returns>The same code matcher</returns>
358360
///
361+
362+
[SuppressMessage("Style", "IDE0300")]
359363
public CodeMatcher CreateLabelWithOffsets(int offset, out Label label)
360364
{
361365
label = generator.DefineLabel();
362-
return AddLabelsAt(Pos + offset, [label]);
366+
return AddLabelsAt(Pos + offset, new Label[] { label });
363367
}
364368

365369
/// <summary>Adds an enumeration of labels to current position</summary>

Harmony/Tools/Extensions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.ComponentModel;
4+
using System.Diagnostics.CodeAnalysis;
45
using System.Linq;
56
using System.Reflection;
67
using System.Reflection.Emit;
@@ -670,7 +671,8 @@ public static void Do<T>(this IEnumerable<T> sequence, Action<T> action)
670671
/// <param name="item">The item to add</param>
671672
/// <returns>The collection containing the item</returns>
672673
///
673-
public static IEnumerable<T> AddItem<T>(this IEnumerable<T> sequence, T item) => (sequence ?? []).Concat([item]);
674+
[SuppressMessage("Style", "IDE0300")]
675+
public static IEnumerable<T> AddItem<T>(this IEnumerable<T> sequence, T item) => (sequence ?? []).Concat(new T[] { item });
674676

675677
/// <summary>A helper to add an item to an array</summary>
676678
/// <typeparam name="T">The inner type of the collection</typeparam>

0 commit comments

Comments
 (0)