diff options
| author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2022-04-13 23:40:47 -0400 | 
|---|---|---|
| committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2022-04-13 23:40:47 -0400 | 
| commit | 66272cbe46b848c64859cd0ab8cca6032c307137 (patch) | |
| tree | ad4ed0aa39a04bc9e2b176f5b92279ff48dff636 /src/SMAPI/Utilities | |
| parent | 045e4ddf2df278f740903294057a67cac8c95052 (diff) | |
| download | SMAPI-66272cbe46b848c64859cd0ab8cca6032c307137.tar.gz SMAPI-66272cbe46b848c64859cd0ab8cca6032c307137.tar.bz2 SMAPI-66272cbe46b848c64859cd0ab8cca6032c307137.zip | |
fix false-positive deprecation notice (#837)
Diffstat (limited to 'src/SMAPI/Utilities')
| -rw-r--r-- | src/SMAPI/Utilities/PerScreen.cs | 43 | 
1 files changed, 26 insertions, 17 deletions
| diff --git a/src/SMAPI/Utilities/PerScreen.cs b/src/SMAPI/Utilities/PerScreen.cs index 799ff63b..ba4f3325 100644 --- a/src/SMAPI/Utilities/PerScreen.cs +++ b/src/SMAPI/Utilities/PerScreen.cs @@ -40,27 +40,12 @@ 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!) { } +            : this(null, nullExpected: true) { }          /// <summary>Construct an instance.</summary>          /// <param name="createNewState">Create the initial state for a screen.</param>          public PerScreen(Func<T> createNewState) -        { -            // 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; -        } +            : this(createNewState, nullExpected: false) { }          /// <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() @@ -98,6 +83,30 @@ 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( +                        SCore.DeprecationManager.GetSourceNameFromStack(), +                        $"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()          { | 
