From dab1ef6acc243726247cee57877c3b3100106522 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Mon, 20 Jun 2022 18:01:48 -0400 Subject: add flag to disable deprecated code --- src/SMAPI/Utilities/PerScreen.cs | 49 +++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 26 deletions(-) (limited to 'src/SMAPI/Utilities') 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 /// Construct an instance. /// Limitation with nullable reference types: when the underlying type 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. public PerScreen() - : this(null, nullExpected: true) { } + { + this.CreateNewState = (() => default!); + } /// Construct an instance. /// Create the initial state for a screen. public PerScreen(Func createNewState) - : this(createNewState, nullExpected: false) { } + { + if (createNewState is null) + { +#if SMAPI_DEPRECATED + createNewState = (() => default!); + SCore.DeprecationManager.Warn( + null, + $"calling the {nameof(PerScreen)} constructor with null", + "3.14.0", + DeprecationLevel.Notice + ); +#else + throw new ArgumentNullException(nameof(createNewState)); +#endif + } + + this.CreateNewState = createNewState; + } /// Get all active values by screen ID. This doesn't initialize the value for a screen ID if it's not created yet. public IEnumerable> GetActiveValues() @@ -84,30 +105,6 @@ namespace StardewModdingAPI.Utilities /********* ** Private methods *********/ - /// Construct an instance. - /// Create the initial state for a screen. - /// Whether a null value is expected. - /// This constructor only exists to maintain backwards compatibility. In SMAPI 4.0.0, the overload that passes nullExpected: false should throw an exception instead. - private PerScreen(Func? createNewState, bool nullExpected) - { - if (createNewState is null) - { - createNewState = (() => default!); - - if (!nullExpected) - { - SCore.DeprecationManager.Warn( - null, - $"calling the {nameof(PerScreen)} constructor with null", - "3.14.0", - DeprecationLevel.Notice - ); - } - } - - this.CreateNewState = createNewState; - } - /// Remove screens which are no longer active. private void RemoveDeadScreens() { -- cgit