about summary refs log tree commit diff
path: root/MatrixRoomUtils.Core/Extensions/DictionaryExtensions.cs
blob: c51baec5b655945fe70c0adcdfeb6ca008d9f99c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
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;
    }
}