Skip to content

Commit

Permalink
Make Flags equality strict about type
Browse files Browse the repository at this point in the history
  • Loading branch information
sliekens committed Jan 26, 2025
1 parent 2d77d59 commit bafb65b
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions GW2SDK/Features/Flags.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ public virtual bool Equals(Flags? other)
{
if (ReferenceEquals(this, other)) return true;
if (other is null) return false;

if (!Other.SequenceEqual(other.Other))
{
return false;
}
if (GetType() != other.GetType()) return false;

var flags = GetType()
.GetProperties(BindingFlags.Public | BindingFlags.Instance)
Expand All @@ -30,7 +26,7 @@ public virtual bool Equals(Flags? other)

var left = flags.Select(property => (bool?)property.GetValue(this));
var right = flags.Select(property => (bool?)property.GetValue(other));
return left.SequenceEqual(right);
return left.SequenceEqual(right) && Other.SequenceEqual(other.Other);
}

/// <inheritdoc />
Expand All @@ -47,6 +43,11 @@ public override int GetHashCode()
hash.Add(flag);
}

foreach (var flag in Other)
{
hash.Add(flag);
}

return hash.ToHashCode();
}

Expand Down

0 comments on commit bafb65b

Please sign in to comment.