IEquatable<T> without Equals(object) (CA1067)
Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.
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.
Incorrect
Section titled “Incorrect”public class Money : IEquatable<Money>{ public bool Equals(Money? other) => other is not null && Amount == other.Amount;}Correct
Section titled “Correct”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();}