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