Skip to content

Commit c2c6cf8

Browse files
committed
Add Remove extension method for Dictionary to facilitate safe key removal
1 parent e5eb58c commit c2c6cf8

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Assets/_PackageRoot/Runtime/Extensions.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,15 @@ public static TValue GetValueOrDefault<TKey, TValue>(this Dictionary<TKey, TValu
2323
{
2424
return dictionary.TryGetValue(key, out var value) ? value : defaultValue;
2525
}
26+
public static bool Remove<TKey, TValue>(this Dictionary<TKey, TValue> dictionary, TKey key, out TValue value)
27+
{
28+
if (dictionary.TryGetValue(key, out value))
29+
{
30+
dictionary.Remove(key);
31+
return true;
32+
}
33+
value = default;
34+
return false;
35+
}
2636
}
2737
}

Assets/_PackageRoot/Runtime/ImageLoader.MemoryCache.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Collections.Concurrent;
21
using System.Collections.Generic;
32
using UnityEngine;
43

0 commit comments

Comments
 (0)