MatrixRoomUtils

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | LICENSE

DictionaryExtensions.cs (419B)


      1 namespace MatrixRoomUtils.Core.Extensions;
      2 
      3 public static class DictionaryExtensions
      4 {
      5     public static bool ChangeKey<TKey, TValue>(this IDictionary<TKey, TValue> dict, 
      6         TKey oldKey, TKey newKey)
      7     {
      8         TValue value;
      9         if (!dict.Remove(oldKey, out value))
     10             return false;
     11 
     12         dict[newKey] = value;  // or dict.Add(newKey, value) depending on ur comfort
     13         return true;
     14     }
     15 }