namespace adas_core.Domain.Utils; public sealed class EquatableDictionary : Dictionary, IEquatable> where TKey : notnull where TValue : notnull { public bool Equals(ComparableDictionary? other) { if (other is null) return false; if (Count != other.Count) return false; foreach (var pair in this) { if (!other.TryGetValue(pair.Key, out var otherValue)) return false; if (!EqualityComparer.Default.Equals(pair.Value, otherValue)) return false; } return true; } //private readonly Dictionary dictionary = new(); public override bool Equals(object? other) { return Equals(other as ComparableDictionary); } public override int GetHashCode() { var hash = 0; foreach (var pair in this) { var miniHash = 17; miniHash = miniHash * 31 + EqualityComparer.Default.GetHashCode(pair.Key); miniHash = miniHash * 31 + EqualityComparer.Default.GetHashCode(pair.Value); hash ^= miniHash; } return hash; } // Implementation of IDictionary<,> which just delegates to the dictionary }