Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor token improvements #2080

Closed
wants to merge 3 commits into from

Conversation

adamsitnik
Copy link
Member

While creating the API design proposal I've noticed that:

  • public Token ctor accepts Symbol, but the property is internal. Some users already asked for exposing in the past (Make Token.Symbol property public #1815)
  • Token does not need to override the quality operators, I have most likely introduced them when I've made it a struct in the past

@@ -46,7 +46,7 @@ internal Token(string? value, TokenType type, Symbol? symbol, int position)
/// <summary>
/// The Symbol represented by the token (if any).
/// </summary>
internal Symbol? Symbol { get; set; }
public Symbol? Symbol { get; internal set; }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should test that this is correctly reassigned when OnlyTake is used.

@@ -59,21 +59,5 @@ internal Token(string? value, TokenType type, Symbol? symbol, int position)

/// <inheritdoc />
public override string ToString() => Value;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Standard guidance (https://learn.microsoft.com/en-us/dotnet/api/system.iequatable-1?view=netstandard-2.0#notes-to-implementers) does suggest we should keep the equality operators for consistency, even if we aren't using them at the moment.

From a personal perspective, I like having the equality operators available since it makes the code simpler when dealing with nullable types, and using the equality operators helps avoid (via compilation errors) accidentally making typos that result in calling type1.Equals(type2) (calling into Type1.Equals(object), always returning false).

using System.CommandLine.Parsing;
using Xunit;

namespace System.CommandLine.Tests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we leveraging file scoped namespaces?
I see at least one file was converted to use them by @jonsequitur in #2226

@adamsitnik adamsitnik closed this Jul 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants