diff --git a/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt b/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt index d42c624ad9..73547d489e 100644 --- a/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt +++ b/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt @@ -277,7 +277,7 @@ System.CommandLine.Completions public abstract class CompletionContext public System.CommandLine.ParseResult ParseResult { get; } public System.String WordToComplete { get; } - public class CompletionItem + public class CompletionItem, System.IEquatable .ctor(System.String label, System.String kind = Value, System.String sortText = null, System.String insertText = null, System.String documentation = null, System.String detail = null) public System.String Detail { get; } public System.String Documentation { get; set; } @@ -285,7 +285,7 @@ System.CommandLine.Completions public System.String Kind { get; } public System.String Label { get; } public System.String SortText { get; } - protected System.Boolean Equals(CompletionItem other) + public System.Boolean Equals(CompletionItem other) public System.Boolean Equals(System.Object obj) public System.Int32 GetHashCode() public System.String ToString() diff --git a/src/System.CommandLine/Completions/CompletionItem.cs b/src/System.CommandLine/Completions/CompletionItem.cs index bfa60b25c6..87fe3e4443 100644 --- a/src/System.CommandLine/Completions/CompletionItem.cs +++ b/src/System.CommandLine/Completions/CompletionItem.cs @@ -6,7 +6,7 @@ namespace System.CommandLine.Completions /// /// Provides details about a command line completion item. /// - public class CompletionItem + public class CompletionItem : IEquatable { /// The label value, which is the text displayed to users and, unless is set, is also used to populate the property. /// The kind of completion item. @@ -66,31 +66,13 @@ public CompletionItem( /// /// Determines whether two completion items are equal. /// - protected bool Equals(CompletionItem other) + public bool Equals(CompletionItem? other) { - return Label == other.Label && Kind == other.Kind; + return other is not null && Label == other.Label && Kind == other.Kind; } /// - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) - { - return false; - } - - if (ReferenceEquals(this, obj)) - { - return true; - } - - if (obj.GetType() != GetType()) - { - return false; - } - - return Equals((CompletionItem)obj); - } + public override bool Equals(object? obj) => Equals(obj as CompletionItem); /// public override int GetHashCode()