Skip to content

Commit f449c2d

Browse files
authored
make CompletionItem implement IEquatable<CompletionItem> (#1991)
1 parent c75c74b commit f449c2d

File tree

2 files changed

+6
-24
lines changed

2 files changed

+6
-24
lines changed

src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,15 +277,15 @@ System.CommandLine.Completions
277277
public abstract class CompletionContext
278278
public System.CommandLine.ParseResult ParseResult { get; }
279279
public System.String WordToComplete { get; }
280-
public class CompletionItem
280+
public class CompletionItem, System.IEquatable<CompletionItem>
281281
.ctor(System.String label, System.String kind = Value, System.String sortText = null, System.String insertText = null, System.String documentation = null, System.String detail = null)
282282
public System.String Detail { get; }
283283
public System.String Documentation { get; set; }
284284
public System.String InsertText { get; }
285285
public System.String Kind { get; }
286286
public System.String Label { get; }
287287
public System.String SortText { get; }
288-
protected System.Boolean Equals(CompletionItem other)
288+
public System.Boolean Equals(CompletionItem other)
289289
public System.Boolean Equals(System.Object obj)
290290
public System.Int32 GetHashCode()
291291
public System.String ToString()

src/System.CommandLine/Completions/CompletionItem.cs

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace System.CommandLine.Completions
66
/// <summary>
77
/// Provides details about a command line completion item.
88
/// </summary>
9-
public class CompletionItem
9+
public class CompletionItem : IEquatable<CompletionItem>
1010
{
1111
/// <param name="label">The label value, which is the text displayed to users and, unless <paramref name="insertText"/> is set, is also used to populate the <see cref="InsertText"/> property.</param>
1212
/// <param name="kind">The kind of completion item.</param>
@@ -66,31 +66,13 @@ public CompletionItem(
6666
/// <summary>
6767
/// Determines whether two completion items are equal.
6868
/// </summary>
69-
protected bool Equals(CompletionItem other)
69+
public bool Equals(CompletionItem? other)
7070
{
71-
return Label == other.Label && Kind == other.Kind;
71+
return other is not null && Label == other.Label && Kind == other.Kind;
7272
}
7373

7474
/// <inheritdoc />
75-
public override bool Equals(object? obj)
76-
{
77-
if (ReferenceEquals(null, obj))
78-
{
79-
return false;
80-
}
81-
82-
if (ReferenceEquals(this, obj))
83-
{
84-
return true;
85-
}
86-
87-
if (obj.GetType() != GetType())
88-
{
89-
return false;
90-
}
91-
92-
return Equals((CompletionItem)obj);
93-
}
75+
public override bool Equals(object? obj) => Equals(obj as CompletionItem);
9476

9577
/// <inheritdoc />
9678
public override int GetHashCode()

0 commit comments

Comments
 (0)