Skip to content

Commit

Permalink
Override KeyValues Equals
Browse files Browse the repository at this point in the history
  • Loading branch information
cooolbros committed Dec 30, 2023
1 parent a56d209 commit 7376d74
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/VDF/Models/KeyValues.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,43 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;

namespace VDF.Models;

public class KeyValues : List<KeyValue>
{
public KeyValues() { }
public KeyValues(IEnumerable<KeyValue> 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();
}
}

0 comments on commit 7376d74

Please sign in to comment.