Ir al contenido

IEquatable<T> without Equals(object) (CA1067)

Esta página aún no está disponible en tu idioma.

Key dotnet.codequality.iequatable-without-equals · Severity warning · Category codequality

Microsoft analyzer CA1067. Flags a type implementing IEquatable<T> without overriding Equals(object). Collections and APIs that call the object overload compare by reference and disagree with the typed one.

public class Money : IEquatable<Money>
{
public bool Equals(Money? other) => other is not null && Amount == other.Amount;
}
public class Money : IEquatable<Money>
{
public bool Equals(Money? other) => other is not null && Amount == other.Amount;
public override bool Equals(object? obj) => Equals(obj as Money);
public override int GetHashCode() => Amount.GetHashCode();
}