From a593eda30f82af474887d91458b0e9158f66fefc Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 6 Apr 2022 18:24:59 -0400 Subject: use target-typed new --- src/SMAPI.Internal.Patching/HarmonyPatcher.cs | 2 +- src/SMAPI.Internal.Patching/PatchHelper.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/SMAPI.Internal.Patching') diff --git a/src/SMAPI.Internal.Patching/HarmonyPatcher.cs b/src/SMAPI.Internal.Patching/HarmonyPatcher.cs index c07e3b41..6f30c241 100644 --- a/src/SMAPI.Internal.Patching/HarmonyPatcher.cs +++ b/src/SMAPI.Internal.Patching/HarmonyPatcher.cs @@ -15,7 +15,7 @@ namespace StardewModdingAPI.Internal.Patching /// The patchers to apply. public static Harmony Apply(string id, IMonitor monitor, params IPatcher[] patchers) { - Harmony harmony = new Harmony(id); + Harmony harmony = new(id); foreach (IPatcher patcher in patchers) { diff --git a/src/SMAPI.Internal.Patching/PatchHelper.cs b/src/SMAPI.Internal.Patching/PatchHelper.cs index fc79ddf2..c9758616 100644 --- a/src/SMAPI.Internal.Patching/PatchHelper.cs +++ b/src/SMAPI.Internal.Patching/PatchHelper.cs @@ -43,7 +43,7 @@ namespace StardewModdingAPI.Internal.Patching /// The method generic types, or null if it's not generic. public static string GetMethodString(Type type, string name, Type[] parameters = null, Type[] generics = null) { - StringBuilder str = new StringBuilder(); + StringBuilder str = new(); // type str.Append(type.FullName); -- cgit From 2e7c233f6c9bf6430672b39f970a3324deba79dd Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 6 Apr 2022 21:48:55 -0400 Subject: enable nullable annotations by default (#837) This adds `#nullable disable` to all existing code (except where null is impossible like enum files), so it can be migrated incrementally. --- src/SMAPI.Internal.Patching/BasePatcher.cs | 2 ++ src/SMAPI.Internal.Patching/HarmonyPatcher.cs | 2 ++ src/SMAPI.Internal.Patching/IPatcher.cs | 2 ++ src/SMAPI.Internal.Patching/PatchHelper.cs | 2 ++ 4 files changed, 8 insertions(+) (limited to 'src/SMAPI.Internal.Patching') diff --git a/src/SMAPI.Internal.Patching/BasePatcher.cs b/src/SMAPI.Internal.Patching/BasePatcher.cs index 87155d7f..6d019b52 100644 --- a/src/SMAPI.Internal.Patching/BasePatcher.cs +++ b/src/SMAPI.Internal.Patching/BasePatcher.cs @@ -1,3 +1,5 @@ +#nullable disable + using System; using System.Reflection; using HarmonyLib; diff --git a/src/SMAPI.Internal.Patching/HarmonyPatcher.cs b/src/SMAPI.Internal.Patching/HarmonyPatcher.cs index 6f30c241..fc239fd2 100644 --- a/src/SMAPI.Internal.Patching/HarmonyPatcher.cs +++ b/src/SMAPI.Internal.Patching/HarmonyPatcher.cs @@ -1,3 +1,5 @@ +#nullable disable + using System; using HarmonyLib; diff --git a/src/SMAPI.Internal.Patching/IPatcher.cs b/src/SMAPI.Internal.Patching/IPatcher.cs index a732d64f..5b373117 100644 --- a/src/SMAPI.Internal.Patching/IPatcher.cs +++ b/src/SMAPI.Internal.Patching/IPatcher.cs @@ -1,3 +1,5 @@ +#nullable disable + using HarmonyLib; namespace StardewModdingAPI.Internal.Patching diff --git a/src/SMAPI.Internal.Patching/PatchHelper.cs b/src/SMAPI.Internal.Patching/PatchHelper.cs index c9758616..52b15fd1 100644 --- a/src/SMAPI.Internal.Patching/PatchHelper.cs +++ b/src/SMAPI.Internal.Patching/PatchHelper.cs @@ -1,3 +1,5 @@ +#nullable disable + using System; using System.Linq; using System.Reflection; -- cgit From c3851ae2e6c8fb286d4744612fbfea039d1baf7f Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Tue, 12 Apr 2022 19:56:52 -0400 Subject: enable nullable annotations in shared projects (#837) --- src/SMAPI.Internal.Patching/BasePatcher.cs | 6 ++---- src/SMAPI.Internal.Patching/HarmonyPatcher.cs | 2 -- src/SMAPI.Internal.Patching/IPatcher.cs | 2 -- src/SMAPI.Internal.Patching/PatchHelper.cs | 8 +++----- 4 files changed, 5 insertions(+), 13 deletions(-) (limited to 'src/SMAPI.Internal.Patching') diff --git a/src/SMAPI.Internal.Patching/BasePatcher.cs b/src/SMAPI.Internal.Patching/BasePatcher.cs index 6d019b52..c1936ccc 100644 --- a/src/SMAPI.Internal.Patching/BasePatcher.cs +++ b/src/SMAPI.Internal.Patching/BasePatcher.cs @@ -1,5 +1,3 @@ -#nullable disable - using System; using System.Reflection; using HarmonyLib; @@ -32,7 +30,7 @@ namespace StardewModdingAPI.Internal.Patching /// The method name. /// The method parameter types, or null if it's not overloaded. /// The method generic types, or null if it's not generic. - protected MethodInfo RequireMethod(string name, Type[] parameters = null, Type[] generics = null) + protected MethodInfo RequireMethod(string name, Type[]? parameters = null, Type[]? generics = null) { return PatchHelper.RequireMethod(name, parameters, generics); } @@ -42,7 +40,7 @@ namespace StardewModdingAPI.Internal.Patching /// The patch priority to apply, usually specified using Harmony's enum, or null to keep the default value. protected HarmonyMethod GetHarmonyMethod(string name, int? priority = null) { - var method = new HarmonyMethod( + HarmonyMethod method = new( AccessTools.Method(this.GetType(), name) ?? throw new InvalidOperationException($"Can't find patcher method {PatchHelper.GetMethodString(this.GetType(), name)}.") ); diff --git a/src/SMAPI.Internal.Patching/HarmonyPatcher.cs b/src/SMAPI.Internal.Patching/HarmonyPatcher.cs index fc239fd2..6f30c241 100644 --- a/src/SMAPI.Internal.Patching/HarmonyPatcher.cs +++ b/src/SMAPI.Internal.Patching/HarmonyPatcher.cs @@ -1,5 +1,3 @@ -#nullable disable - using System; using HarmonyLib; diff --git a/src/SMAPI.Internal.Patching/IPatcher.cs b/src/SMAPI.Internal.Patching/IPatcher.cs index 5b373117..a732d64f 100644 --- a/src/SMAPI.Internal.Patching/IPatcher.cs +++ b/src/SMAPI.Internal.Patching/IPatcher.cs @@ -1,5 +1,3 @@ -#nullable disable - using HarmonyLib; namespace StardewModdingAPI.Internal.Patching diff --git a/src/SMAPI.Internal.Patching/PatchHelper.cs b/src/SMAPI.Internal.Patching/PatchHelper.cs index 52b15fd1..edd8ef57 100644 --- a/src/SMAPI.Internal.Patching/PatchHelper.cs +++ b/src/SMAPI.Internal.Patching/PatchHelper.cs @@ -1,5 +1,3 @@ -#nullable disable - using System; using System.Linq; using System.Reflection; @@ -18,7 +16,7 @@ namespace StardewModdingAPI.Internal.Patching /// The type containing the method. /// The method parameter types, or null if it's not overloaded. /// The type has no matching constructor. - public static ConstructorInfo RequireConstructor(Type[] parameters = null) + public static ConstructorInfo RequireConstructor(Type[]? parameters = null) { return AccessTools.Constructor(typeof(TTarget), parameters) @@ -31,7 +29,7 @@ namespace StardewModdingAPI.Internal.Patching /// The method parameter types, or null if it's not overloaded. /// The method generic types, or null if it's not generic. /// The type has no matching method. - public static MethodInfo RequireMethod(string name, Type[] parameters = null, Type[] generics = null) + public static MethodInfo RequireMethod(string name, Type[]? parameters = null, Type[]? generics = null) { return AccessTools.Method(typeof(TTarget), name, parameters, generics) @@ -43,7 +41,7 @@ namespace StardewModdingAPI.Internal.Patching /// The method name, or null for a constructor. /// The method parameter types, or null if it's not overloaded. /// The method generic types, or null if it's not generic. - public static string GetMethodString(Type type, string name, Type[] parameters = null, Type[] generics = null) + public static string GetMethodString(Type type, string? name, Type[]? parameters = null, Type[]? generics = null) { StringBuilder str = new(); -- cgit