From 39cce0ad353905e77660612af5a84e90eca7518a Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Tue, 14 Jan 2025 05:54:21 +1100 Subject: [PATCH] obsolete AddOrSet (#7408) * obsolete AddOrSet * added API approvals --------- Co-authored-by: Aaron Stannard Co-authored-by: Gregorius Soedharmo --- .../verify/CoreAPISpec.ApproveCore.DotNet.verified.txt | 1 + .../verify/CoreAPISpec.ApproveCore.Net.verified.txt | 1 + src/core/Akka/Util/Internal/Extensions.cs | 8 +++----- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveCore.DotNet.verified.txt b/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveCore.DotNet.verified.txt index b16d008ad18..68130c8810e 100644 --- a/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveCore.DotNet.verified.txt +++ b/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveCore.DotNet.verified.txt @@ -5642,6 +5642,7 @@ namespace Akka.Util.Internal public class static Extensions { public static System.Collections.Generic.IDictionary AddAndReturn(this System.Collections.Generic.IDictionary hash, TKey key, TValue value) { } + [System.ObsoleteAttribute("Use the dictionary setter directly")] public static void AddOrSet(this System.Collections.Generic.IDictionary hash, TKey key, TValue value) { } public static T AsInstanceOf(this object self) { } public static string BetweenDoubleQuotes(this string self) { } diff --git a/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveCore.Net.verified.txt b/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveCore.Net.verified.txt index b1c6cb7b794..f109a52de5c 100644 --- a/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveCore.Net.verified.txt +++ b/src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveCore.Net.verified.txt @@ -5631,6 +5631,7 @@ namespace Akka.Util.Internal public class static Extensions { public static System.Collections.Generic.IDictionary AddAndReturn(this System.Collections.Generic.IDictionary hash, TKey key, TValue value) { } + [System.ObsoleteAttribute("Use the dictionary setter directly")] public static void AddOrSet(this System.Collections.Generic.IDictionary hash, TKey key, TValue value) { } public static T AsInstanceOf(this object self) { } public static string BetweenDoubleQuotes(this string self) { } diff --git a/src/core/Akka/Util/Internal/Extensions.cs b/src/core/Akka/Util/Internal/Extensions.cs index 5e74be8e3c8..51924ee4e00 100644 --- a/src/core/Akka/Util/Internal/Extensions.cs +++ b/src/core/Akka/Util/Internal/Extensions.cs @@ -111,12 +111,10 @@ public static string BetweenDoubleQuotes(this string self) /// TBD /// TBD /// TBD + [Obsolete("Use the dictionary setter directly")] public static void AddOrSet(this IDictionary hash, TKey key, TValue value) { - if (hash.ContainsKey(key)) - hash[key] = value; - else - hash.Add(key,value); + hash[key] = value; } /// @@ -146,7 +144,7 @@ public static TValue GetOrElse(this IDictionary hash /// TBD public static IDictionary AddAndReturn(this IDictionary hash, TKey key, TValue value) { - hash.AddOrSet(key, value); + hash[key] = value; return hash; }