From 1d02d9d76d987b69ed08a252a3fa66f7d05a4cbc Mon Sep 17 00:00:00 2001 From: TheArcaneBrony Date: Mon, 4 Sep 2023 02:16:40 +0200 Subject: Clean up some extension functions --- LibMatrix/Extensions/DictionaryExtensions.cs | 32 ---------------------------- 1 file changed, 32 deletions(-) delete mode 100644 LibMatrix/Extensions/DictionaryExtensions.cs (limited to 'LibMatrix/Extensions/DictionaryExtensions.cs') diff --git a/LibMatrix/Extensions/DictionaryExtensions.cs b/LibMatrix/Extensions/DictionaryExtensions.cs deleted file mode 100644 index f01cf68..0000000 --- a/LibMatrix/Extensions/DictionaryExtensions.cs +++ /dev/null @@ -1,32 +0,0 @@ -namespace LibMatrix.Extensions; - -public static class DictionaryExtensions { - public static bool ChangeKey(this IDictionary dict, - TKey oldKey, TKey newKey) { - if (!dict.Remove(oldKey, out var value)) - return false; - - dict[newKey] = value; // or dict.Add(newKey, value) depending on ur comfort - return true; - } - - public static Y GetOrCreate(this IDictionary 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(this IDictionary dict, X key, Func valueFactory) { - if (dict.TryGetValue(key, out var value)) { - return value; - } - - value = valueFactory(key); - dict.Add(key, value); - return value; - } -} -- cgit 1.4.1