diff --git a/.openpublishing.redirection.json b/.openpublishing.redirection.json index 33bd2a13da9a3..56ad02ad40fb6 100644 --- a/.openpublishing.redirection.json +++ b/.openpublishing.redirection.json @@ -2994,6 +2994,10 @@ "source_path": "docs/desktop-wpf/xaml-services/xuid-directive.md", "redirect_url": "/dotnet/desktop/xaml-services/xuid-directive" }, + { + "source_path": "docs/fundamentals/code-analysis/quality-rules/ca1067.md", + "redirect_url": "/dotnet/fundamentals/code-analysis/quality-rules/index" + }, { "source_path": "docs/fundamentals/code-analysis/style-rules/ide0003.md", "redirect_url": "/dotnet/fundamentals/code-analysis/style-rules/ide0003-ide0009" diff --git a/docs/fundamentals/code-analysis/quality-rules/ca1067.md b/docs/fundamentals/code-analysis/quality-rules/ca1067.md deleted file mode 100644 index 18f23fb8ad616..0000000000000 --- a/docs/fundamentals/code-analysis/quality-rules/ca1067.md +++ /dev/null @@ -1,83 +0,0 @@ ---- -title: "CA1067: Override Equals when implementing IEquatable (code analysis)" -description: "Learn about code analysis rule CA1067: Override Equals when implementing IEquatable" -ms.date: 04/23/2020 -ms.topic: reference -f1_keywords: -- CA1067 -helpviewer_keywords: -- CA1067 -author: mavasani -ms.author: mavasani ---- -# CA1067: Override Equals when implementing IEquatable - -| | Value | -|-|-| -| **Rule ID** |CA1067| -| **Category** |[Microsoft.Design](design-warnings.md)| -| **Fix is breaking or non-breaking** |Non-breaking| - -## Cause - -A type implements , but does not override method. - -## Rule description - -A type implementing interface indicates that it supports comparing two instances of the type for equality. You should also override the base class implementations of and methods so that their behavior is consistent with that of the implementation. See [here](/dotnet/api/system.iequatable-1#notes-to-implementers) for more details. - -Your implementation should return results that are consistent with implementation. - -## How to fix violations - -To fix a violation, override and implement it by invoking the implementation. For example, the following two code snippets show a violation of the rule and how to fix it: - -```csharp -using System; - -public struct S : IEquatable -{ - private readonly int _value; - public S(int f) - { - _value = f; - } - - public bool Equals(S other) - => _value == other._value; -} -``` - -```csharp -using System; - -public struct S : IEquatable -{ - private readonly int _value; - public S(int f) - { - _value = f; - } - - public bool Equals(S other) - => _value == other._value; - - public override bool Equals(object obj) - => obj is S objS && Equals(objS); - - public override int GetHashCode() - => _value.GetHashCode(); -} -``` - -## When to suppress warnings - -Do not suppress violations of this rule. - -## Related rules - -- [CA1066: Implement IEquatable when overriding Equals](ca1066.md) - -## See also - -- [Design rules](design-warnings.md)