Skip to content

Commit

Permalink
refactor: simplify code of equals
Browse files Browse the repository at this point in the history
  • Loading branch information
meaboutsoftware committed Jun 18, 2024
1 parent ad25701 commit 8a5dea2
Showing 1 changed file with 3 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace EvolutionaryArchitecture.Fitnet.Common.Core;
namespace EvolutionaryArchitecture.Fitnet.Common.Core;

public abstract class ValueObject : IEquatable<ValueObject>
{
Expand All @@ -7,17 +7,8 @@ public abstract class ValueObject : IEquatable<ValueObject>
public bool Equals(ValueObject? other) =>
other is not null && GetType() == other.GetType() && IsSequenceEqual(other);

public override bool Equals(object? obj)
{
if (obj is null || obj.GetType() != GetType())
{
return false;
}

var other = (ValueObject)obj;

return IsSequenceEqual(other);
}
public override bool Equals(object? obj) =>
obj is ValueObject valueObject && Equals(valueObject);

public override int GetHashCode() => GetEqualityComponents()
.Aggregate(default(int), (current, obj) => HashCode.Combine(current, obj.GetHashCode()));
Expand Down

0 comments on commit 8a5dea2

Please sign in to comment.