diff --git a/src/System.CommandLine/Parsing/Token.cs b/src/System.CommandLine/Parsing/Token.cs index 7b656c9886..85d2187359 100644 --- a/src/System.CommandLine/Parsing/Token.cs +++ b/src/System.CommandLine/Parsing/Token.cs @@ -6,7 +6,7 @@ namespace System.CommandLine.Parsing /// /// A unit of significant text on the command line. /// - public class Token : IEquatable + public sealed class Token : IEquatable { internal const int ImplicitPosition = -1; @@ -66,7 +66,7 @@ internal Token(string? value, TokenType type, Symbol? symbol, int position) /// The first . /// The second . /// if the objects are equal. - public static bool operator ==(Token left, Token right) => left.Equals(right); + public static bool operator ==(Token left, Token right) => left?.Equals(right) ?? right is null; /// /// Checks if two specified instances have different values. @@ -74,6 +74,6 @@ internal Token(string? value, TokenType type, Symbol? symbol, int position) /// The first . /// The second . /// if the objects are not equal. - public static bool operator !=(Token left, Token right) => !left.Equals(right); + public static bool operator !=(Token left, Token right) => !(left == right); } }