Skip to content

Commit

Permalink
reverts some [] syntax so it compiles in all .net versions
Browse files Browse the repository at this point in the history
  • Loading branch information
pardeike committed Feb 19, 2024
1 parent 9615407 commit 16f00a1
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
6 changes: 5 additions & 1 deletion Harmony/Internal/HarmonySharedState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -109,9 +111,11 @@ internal static PatchInfo GetPatchInfo(MethodBase method)
return PatchInfoSerialization.Deserialize(bytes);
}


[SuppressMessage("Style", "IDE0305")]
internal static IEnumerable<MethodBase> GetPatchedMethods()
{
lock (state) return [.. state.Keys];
lock (state) return state.Keys.ToArray();
}

internal static void UpdatePatchInfo(MethodBase original, MethodInfo replacement, PatchInfo patchInfo)
Expand Down
7 changes: 5 additions & 2 deletions Harmony/Public/PatchClassProcessor.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;

Expand Down Expand Up @@ -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<S, T>(T defaultIfNotExisting, T defaultIfFailing, Func<T, string> 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)
Expand Down Expand Up @@ -312,11 +314,12 @@ T RunMethod<S, T>(T defaultIfNotExisting, T defaultIfFailing, Func<T, string> fa
return defaultIfNotExisting;
}

[SuppressMessage("Style", "IDE0300")]
void RunMethod<S>(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
{
Expand Down
8 changes: 6 additions & 2 deletions Harmony/Tools/CodeMatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Diagnostics.CodeAnalysis;

namespace HarmonyLib
{
Expand Down Expand Up @@ -344,10 +345,11 @@ public CodeMatcher CreateLabel(out Label label)
/// <param name="label">[out] The new label</param>
/// <returns>The same code matcher</returns>
///
[SuppressMessage("Style", "IDE0300")]
public CodeMatcher CreateLabelAt(int position, out Label label)
{
label = generator.DefineLabel();
_ = AddLabelsAt(position, [label]);
_ = AddLabelsAt(position, new Label[] { label });
return this;
}

Expand All @@ -356,10 +358,12 @@ public CodeMatcher CreateLabelAt(int position, out Label label)
/// <param name="label">[out] The new label</param>
/// <returns>The same code matcher</returns>
///

[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 });
}

/// <summary>Adds an enumeration of labels to current position</summary>
Expand Down
4 changes: 3 additions & 1 deletion Harmony/Tools/Extensions.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -670,7 +671,8 @@ public static void Do<T>(this IEnumerable<T> sequence, Action<T> action)
/// <param name="item">The item to add</param>
/// <returns>The collection containing the item</returns>
///
public static IEnumerable<T> AddItem<T>(this IEnumerable<T> sequence, T item) => (sequence ?? []).Concat([item]);
[SuppressMessage("Style", "IDE0300")]
public static IEnumerable<T> AddItem<T>(this IEnumerable<T> sequence, T item) => (sequence ?? []).Concat(new T[] { item });

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

0 comments on commit 16f00a1

Please sign in to comment.