using System.Collections.Immutable; namespace InnovEnergy.Lib.Protocols.DBus.Daemon; // TODO #pragma warning disable CS8714 public record ObservableDictionary ( IReadOnlyList> Added, IReadOnlyList> Removed, IReadOnlyList> Changed, ImmutableDictionary Items ) { private static KeyValuePair[] Nothing { get; } = Array.Empty>(); public static ObservableDictionary Empty { get; } = new ObservableDictionary(Nothing, Nothing, Nothing, ImmutableDictionary.Empty); public ObservableDictionary Add(K key, V value) { var added = new[] { new KeyValuePair(key, value) }; return new ObservableDictionary(added, Nothing, Nothing, Items.Add(key, value)); } public ObservableDictionary AddRange(params KeyValuePair[] added) { return new ObservableDictionary(added, Nothing, Nothing, Items.AddRange(added)); } public ObservableDictionary SetItem(K key, V value) { var added = new[] { new KeyValuePair(key, value) }; return new ObservableDictionary(added, Nothing, Nothing, Items.SetItem(key, value)); } public ObservableDictionary SetItems(params KeyValuePair[] items) { return new ObservableDictionary(items, Nothing, Nothing, Items.SetItems(items)); } // public ObservableDictionary Remove(params K[] removed) // { // return new ObservableDictionary(Nothing, removed, Nothing, Items.RemoveRange(removed)); // } };