summaryrefslogtreecommitdiff
path: root/src/SMAPI/Utilities
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI/Utilities')
-rw-r--r--src/SMAPI/Utilities/KeybindList.cs2
-rw-r--r--src/SMAPI/Utilities/PerScreen.cs23
2 files changed, 19 insertions, 6 deletions
diff --git a/src/SMAPI/Utilities/KeybindList.cs b/src/SMAPI/Utilities/KeybindList.cs
index 18eeb9fd..aa12a37a 100644
--- a/src/SMAPI/Utilities/KeybindList.cs
+++ b/src/SMAPI/Utilities/KeybindList.cs
@@ -50,7 +50,7 @@ namespace StardewModdingAPI.Utilities
/// <param name="input">The keybind string. See remarks on <see cref="ToString"/> for format details.</param>
/// <param name="parsed">The parsed keybind list, if valid.</param>
/// <param name="errors">The errors that occurred while parsing the input, if any.</param>
- public static bool TryParse(string input, [NotNullWhen(true)] out KeybindList? parsed, out string[] errors)
+ public static bool TryParse(string? input, [NotNullWhen(true)] out KeybindList? parsed, out string[] errors)
{
// empty input
if (string.IsNullOrWhiteSpace(input))
diff --git a/src/SMAPI/Utilities/PerScreen.cs b/src/SMAPI/Utilities/PerScreen.cs
index afe3ba91..799ff63b 100644
--- a/src/SMAPI/Utilities/PerScreen.cs
+++ b/src/SMAPI/Utilities/PerScreen.cs
@@ -1,8 +1,7 @@
-#nullable disable
-
using System;
using System.Collections.Generic;
using System.Linq;
+using StardewModdingAPI.Framework;
namespace StardewModdingAPI.Utilities
{
@@ -39,14 +38,28 @@ namespace StardewModdingAPI.Utilities
** Public methods
*********/
/// <summary>Construct an instance.</summary>
+ /// <remarks><strong>Limitation with nullable reference types:</strong> when the underlying type <typeparamref name="T"/> is nullable, this sets the default value to null regardless of whether you marked the type parameter nullable. To avoid that, set the default value with the 'createNewState' argument instead.</remarks>
public PerScreen()
- : this(null) { }
+ : this(null!) { }
/// <summary>Construct an instance.</summary>
/// <param name="createNewState">Create the initial state for a screen.</param>
public PerScreen(Func<T> createNewState)
{
- this.CreateNewState = createNewState ?? (() => default);
+ // ReSharper disable once ConditionIsAlwaysTrueOrFalse -- required for backwards compatibility
+ if (createNewState is null)
+ {
+ SCore.DeprecationManager.Warn(
+ SCore.DeprecationManager.GetSourceNameFromStack(),
+ $"calling the {nameof(PerScreen<T>)} constructor with null",
+ "3.14.0",
+ DeprecationLevel.Notice
+ );
+
+ createNewState = (() => default!);
+ }
+
+ this.CreateNewState = createNewState;
}
/// <summary>Get all active values by screen ID. This doesn't initialize the value for a screen ID if it's not created yet.</summary>
@@ -61,7 +74,7 @@ namespace StardewModdingAPI.Utilities
public T GetValueForScreen(int screenId)
{
this.RemoveDeadScreens();
- return this.States.TryGetValue(screenId, out T state)
+ return this.States.TryGetValue(screenId, out T? state)
? state
: this.States[screenId] = this.CreateNewState();
}