Why does this simple test fail?
var dict1 = new Dictionary<int, int> {{1, 15}};
var dict2 = new Dictionary<int, int> {{1, 15}};
var equals = EqualityComparer<IDictionary<int, int>>.Default.Equals(dict1, dict2);
Assert.IsTrue(equals);
...thank you very much. I ended up with my own dictionary... Does this look like something one would and should do?
public class EquatableDictionary<TKey, TValue> : Dictionary<TKey, TValue>, IEquatable<EquatableDictionary<TKey, TValue>>
{
public EquatableDictionary() { }
protected EquatableDictionary(SerializationInfo info, StreamingContext context) : base(info, context)
{
}
public bool Equals(EquatableDictionary<TKey, TValue> other)
{
if (other == null)
return false;
foreach (var kvp in this)
{
if (!other.TryGetValue(kvp.Key, out var otherValue))
return false;
if (!Equals(kvp.Value, otherValue))
return false;
}
return true;
}
}