using Lookup.Interface; using System; using System.Collections.Generic; using System.Runtime.Serialization; namespace Lookup.Abstract; /// /// Basic implementation /// /// Type of the key referencing the s /// Type of the stored values, referenced by public abstract class Lookup : Dictionary>, ILookup where TKey : notnull { #region Constructor /// protected Lookup() { } /// protected Lookup(IDictionary> dictionary) : base(dictionary) { } /// protected Lookup( IDictionary> dictionary, IEqualityComparer? comparer ) : base(dictionary, comparer) { } /// protected Lookup(IEnumerable>> collection) : base(collection) { } /// protected Lookup( IEnumerable>> collection, IEqualityComparer? comparer ) : base(collection, comparer) { } /// protected Lookup(IEqualityComparer? comparer) : base(comparer) { } /// protected Lookup(int capacity) : base(capacity) { } /// protected Lookup(int capacity, IEqualityComparer? comparer) : base(capacity, comparer) { } /// protected Lookup(SerializationInfo info, StreamingContext context) : base(info, context) { } #endregion #region Implementation of IDictionary> /// public void Add(TKey key, TValue value) { var collection = TryGetValue(key, out var values) ? values : Add(key); collection.Add(value); } /// public void AddRange(TKey key, IEnumerable values) { var collection = TryGetValue(key, out var existingCollection) ? existingCollection : Add(key); foreach (var value in values) { collection.Add(value); } } /// public bool Remove(TKey key, TValue value) { if (!TryGetValue(key, out var values)) { return false; } values.Remove(value); return true; } /// public ICollection GetOrAdd(TKey key) { return TryGetValue(key, out var values) ? values : Add(key); } #endregion #region Implementation of ILookup /// public abstract ICollection Add(TKey key); #endregion #region Implementation of IDisposable /// protected virtual void Dispose(bool disposing) { } /// public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } #endregion }