diff --git a/src/VDF/Models/KeyValues.cs b/src/VDF/Models/KeyValues.cs index 47911af..9d40459 100644 --- a/src/VDF/Models/KeyValues.cs +++ b/src/VDF/Models/KeyValues.cs @@ -1,6 +1,7 @@ using System; using System.Linq; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; namespace VDF.Models; @@ -8,4 +9,35 @@ public class KeyValues : List { public KeyValues() { } public KeyValues(IEnumerable collection) : base(collection) { } + + public override bool Equals([NotNullWhen(true)] object? obj) + { + if (obj == null || GetType() != obj.GetType()) + { + return false; + } + + return this.SequenceEqual((KeyValues)obj); + } + + public bool Equals([NotNullWhen(true)] object? obj, KeyValueComparer comparer) + { + if (obj == null || GetType() != obj.GetType()) + { + return false; + } + + return this.SequenceEqual((KeyValues)obj, comparer); + } + + public override int GetHashCode() + { + HashCode hash = new(); + foreach (KeyValue kv in this) + { + hash.Add(kv); + } + + return hash.ToHashCode(); + } }