diff --git a/Bencodex.Tests/Types/DictionaryTest.cs b/Bencodex.Tests/Types/DictionaryTest.cs index a9c914b..532d7b8 100644 --- a/Bencodex.Tests/Types/DictionaryTest.cs +++ b/Bencodex.Tests/Types/DictionaryTest.cs @@ -3,15 +3,10 @@ using System.Collections.Immutable; using System.Linq; using System.Text; -using Bencodex.Misc; using Bencodex.Types; -using SharpYaml.Tokens; using Xunit; using static Bencodex.Misc.ImmutableByteArrayExtensions; using static Bencodex.Tests.TestUtils; -using IEquatableDict = System.IEquatable>; namespace Bencodex.Tests.Types { diff --git a/Bencodex/Types/Dictionary.cs b/Bencodex/Types/Dictionary.cs index dca61a7..239fd16 100644 --- a/Bencodex/Types/Dictionary.cs +++ b/Bencodex/Types/Dictionary.cs @@ -17,7 +17,6 @@ namespace Bencodex.Types public sealed class Dictionary : IValue, IEquatable, - IEquatable>, IImmutableDictionary { /// @@ -1697,54 +1696,31 @@ public T GetValue(byte[] name) return (T)this[name]; } - /// - public override bool Equals(object obj) => - obj switch - { - null => false, - Dictionary d => Equals(d), - _ => false, - }; + public override bool Equals(object obj) => obj is Dictionary d && Equals(d); - /// - public bool Equals(Dictionary other) => - Fingerprint.Equals(other.Fingerprint); + public bool Equals(IValue other) => other is Dictionary d && Equals(d); - /// - bool IEquatable>.Equals( - IImmutableDictionary other - ) + public bool Equals(Dictionary other) { - if (_dict.Count != other.Count) - { - return false; - } - else if (other is Dictionary od) + if (Count == other.Count) { - return od.Fingerprint.Equals(Fingerprint); - } - - foreach (KeyValuePair kv in _dict) - { - if (!other.TryGetValue(kv.Key, out IValue v)) + foreach (KeyValuePair kv in _dict) { - return false; + if (!other.TryGetValue(kv.Key, out IValue v) || + !kv.Value.Equals(v)) + { + return false; + } } - if (!kv.Value.Equals(v)) - { - return false; - } + return true; + } + else + { + return false; } - - return true; } - /// - bool IEquatable.Equals(IValue other) => - other is Dictionary o && - ((IEquatable>)this).Equals(o); - /// public override int GetHashCode() => unchecked(_dict.Aggregate(GetType().GetHashCode(), (accum, next)