diff options
author | Emma@Rory& <root@rory.gay> | 2023-08-14 05:07:51 +0200 |
---|---|---|
committer | Emma@Rory& <root@rory.gay> | 2023-08-14 05:11:21 +0200 |
commit | aa7026a17ededf7c181ed269c6388491d96e1b1e (patch) | |
tree | 963b45cebbfefb3c5cebaf4ba7134a0e32eb0147 /MatrixRoomUtils.Core/Extensions/DictionaryExtensions.cs | |
parent | Add latest code before splitting projects (diff) | |
download | MatrixUtils-aa7026a17ededf7c181ed269c6388491d96e1b1e.tar.xz |
Split LibMatrix into submodule
Diffstat (limited to 'MatrixRoomUtils.Core/Extensions/DictionaryExtensions.cs')
-rw-r--r-- | MatrixRoomUtils.Core/Extensions/DictionaryExtensions.cs | 33 |
1 files changed, 0 insertions, 33 deletions
diff --git a/MatrixRoomUtils.Core/Extensions/DictionaryExtensions.cs b/MatrixRoomUtils.Core/Extensions/DictionaryExtensions.cs deleted file mode 100644 index 78bbdfa..0000000 --- a/MatrixRoomUtils.Core/Extensions/DictionaryExtensions.cs +++ /dev/null @@ -1,33 +0,0 @@ -namespace MatrixRoomUtils.Core.Extensions; - -public static class DictionaryExtensions { - public static bool ChangeKey<TKey, TValue>(this IDictionary<TKey, TValue> dict, - TKey oldKey, TKey newKey) { - TValue value; - if (!dict.Remove(oldKey, out value)) - return false; - - dict[newKey] = value; // or dict.Add(newKey, value) depending on ur comfort - return true; - } - - public static Y GetOrCreate<X, Y>(this IDictionary<X, Y> dict, X key) where Y : new() { - if (dict.TryGetValue(key, out var value)) { - return value; - } - - value = new Y(); - dict.Add(key, value); - return value; - } - - public static Y GetOrCreate<X, Y>(this IDictionary<X, Y> dict, X key, Func<X, Y> valueFactory) { - if (dict.TryGetValue(key, out var value)) { - return value; - } - - value = valueFactory(key); - dict.Add(key, value); - return value; - } -} |