summaryrefslogtreecommitdiff
path: root/src/SMAPI/Utilities/PerScreen.cs
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-06-20 18:01:48 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2022-06-20 18:01:48 -0400
commitdab1ef6acc243726247cee57877c3b3100106522 (patch)
tree627610696a998621327fb019586f956b9360bb95 /src/SMAPI/Utilities/PerScreen.cs
parente0ef8a20a5e7ccf1de32ff1a06f1aa62e37eb1db (diff)
downloadSMAPI-dab1ef6acc243726247cee57877c3b3100106522.tar.gz
SMAPI-dab1ef6acc243726247cee57877c3b3100106522.tar.bz2
SMAPI-dab1ef6acc243726247cee57877c3b3100106522.zip
add flag to disable deprecated code
Diffstat (limited to 'src/SMAPI/Utilities/PerScreen.cs')
-rw-r--r--src/SMAPI/Utilities/PerScreen.cs49
1 files changed, 23 insertions, 26 deletions
diff --git a/src/SMAPI/Utilities/PerScreen.cs b/src/SMAPI/Utilities/PerScreen.cs
index b86310b8..54657ade 100644
--- a/src/SMAPI/Utilities/PerScreen.cs
+++ b/src/SMAPI/Utilities/PerScreen.cs
@@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using System.Linq;
+#if SMAPI_DEPRECATED
using StardewModdingAPI.Framework;
using StardewModdingAPI.Framework.Deprecations;
+#endif
namespace StardewModdingAPI.Utilities
{
@@ -41,12 +43,31 @@ namespace StardewModdingAPI.Utilities
/// <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, nullExpected: true) { }
+ {
+ this.CreateNewState = (() => default!);
+ }
/// <summary>Construct an instance.</summary>
/// <param name="createNewState">Create the initial state for a screen.</param>
public PerScreen(Func<T> createNewState)
- : this(createNewState, nullExpected: false) { }
+ {
+ if (createNewState is null)
+ {
+#if SMAPI_DEPRECATED
+ createNewState = (() => default!);
+ SCore.DeprecationManager.Warn(
+ null,
+ $"calling the {nameof(PerScreen<T>)} constructor with null",
+ "3.14.0",
+ DeprecationLevel.Notice
+ );
+#else
+ throw new ArgumentNullException(nameof(createNewState));
+#endif
+ }
+
+ 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>
public IEnumerable<KeyValuePair<int, T>> GetActiveValues()
@@ -84,30 +105,6 @@ namespace StardewModdingAPI.Utilities
/*********
** Private methods
*********/
- /// <summary>Construct an instance.</summary>
- /// <param name="createNewState">Create the initial state for a screen.</param>
- /// <param name="nullExpected">Whether a null <paramref name="createNewState"/> value is expected.</param>
- /// <remarks>This constructor only exists to maintain backwards compatibility. In SMAPI 4.0.0, the overload that passes <c>nullExpected: false</c> should throw an exception instead.</remarks>
- private PerScreen(Func<T>? createNewState, bool nullExpected)
- {
- if (createNewState is null)
- {
- createNewState = (() => default!);
-
- if (!nullExpected)
- {
- SCore.DeprecationManager.Warn(
- null,
- $"calling the {nameof(PerScreen<T>)} constructor with null",
- "3.14.0",
- DeprecationLevel.Notice
- );
- }
- }
-
- this.CreateNewState = createNewState;
- }
-
/// <summary>Remove screens which are no longer active.</summary>
private void RemoveDeadScreens()
{