Skip to content

Commit 39cce0a

Browse files
SimonCroppAarononthewebArkatufus
authored
obsolete AddOrSet (#7408)
* obsolete AddOrSet * added API approvals --------- Co-authored-by: Aaron Stannard <aaron@petabridge.com> Co-authored-by: Gregorius Soedharmo <arkatufus@yahoo.com>
1 parent f362af5 commit 39cce0a

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveCore.DotNet.verified.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5642,6 +5642,7 @@ namespace Akka.Util.Internal
56425642
public class static Extensions
56435643
{
56445644
public static System.Collections.Generic.IDictionary<TKey, TValue> AddAndReturn<TKey, TValue>(this System.Collections.Generic.IDictionary<TKey, TValue> hash, TKey key, TValue value) { }
5645+
[System.ObsoleteAttribute("Use the dictionary setter directly")]
56455646
public static void AddOrSet<TKey, TValue>(this System.Collections.Generic.IDictionary<TKey, TValue> hash, TKey key, TValue value) { }
56465647
public static T AsInstanceOf<T>(this object self) { }
56475648
public static string BetweenDoubleQuotes(this string self) { }

src/core/Akka.API.Tests/verify/CoreAPISpec.ApproveCore.Net.verified.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5631,6 +5631,7 @@ namespace Akka.Util.Internal
56315631
public class static Extensions
56325632
{
56335633
public static System.Collections.Generic.IDictionary<TKey, TValue> AddAndReturn<TKey, TValue>(this System.Collections.Generic.IDictionary<TKey, TValue> hash, TKey key, TValue value) { }
5634+
[System.ObsoleteAttribute("Use the dictionary setter directly")]
56345635
public static void AddOrSet<TKey, TValue>(this System.Collections.Generic.IDictionary<TKey, TValue> hash, TKey key, TValue value) { }
56355636
public static T AsInstanceOf<T>(this object self) { }
56365637
public static string BetweenDoubleQuotes(this string self) { }

src/core/Akka/Util/Internal/Extensions.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,10 @@ public static string BetweenDoubleQuotes(this string self)
111111
/// <param name="hash">TBD</param>
112112
/// <param name="key">TBD</param>
113113
/// <param name="value">TBD</param>
114+
[Obsolete("Use the dictionary setter directly")]
114115
public static void AddOrSet<TKey, TValue>(this IDictionary<TKey, TValue> hash, TKey key, TValue value)
115116
{
116-
if (hash.ContainsKey(key))
117-
hash[key] = value;
118-
else
119-
hash.Add(key,value);
117+
hash[key] = value;
120118
}
121119

122120
/// <summary>
@@ -146,7 +144,7 @@ public static TValue GetOrElse<TKey, TValue>(this IDictionary<TKey, TValue> hash
146144
/// <returns>TBD</returns>
147145
public static IDictionary<TKey, TValue> AddAndReturn<TKey, TValue>(this IDictionary<TKey, TValue> hash, TKey key, TValue value)
148146
{
149-
hash.AddOrSet(key, value);
147+
hash[key] = value;
150148
return hash;
151149
}
152150

0 commit comments

Comments
 (0)