Skip to content

Consider a different return type for Symbol.Aliases #1945

Closed

Description

@jonsequitur
    public abstract class IdentifierSymbol : Symbol, ICompletionSource 
    {
        // "Is this the right return type?"
        public IReadOnlyCollection<string> Aliases { get; }

Related: #1859

Activity

  1. added
    needs discussion
    on Nov 2, 2022
  2. added this to the 2.0 GA milestone on Nov 9, 2022
  3. KalleOlaviNiemitalo commented on Nov 10, 2022

    @KalleOlaviNiemitalo

    I totally expected option.Aliases[0] to work, but it requires Enumerable.First instead.

    In System.CommandLine 2.0.0-beta4.22272.1, the collection is a HashSet<string> and thus does not preserve order. However, I feel it might be better to preserve order here and instead make the parser build a Dictionary<string, Symbol>.

    private protected readonly HashSet<string> _aliases = new(StringComparer.Ordinal);

    /// <summary>
    /// Gets the set of strings that can be used on the command line to specify the symbol.
    /// </summary>
    public IReadOnlyCollection<string> Aliases => _aliases;

  4. KalleOlaviNiemitalo commented on Mar 29, 2023

    @KalleOlaviNiemitalo

    Since #2073, it is ICollection<string> Aliases { get; }, backed by internal class AliasSet:

    public ICollection<string> Aliases => _aliases ??= new();

    public ICollection<string> Aliases => _aliases ??= new();

    internal sealed class AliasSet : ICollection<string>

    (Argument and Directive do not have an Aliases property. It would not be useful for Argument, but could be for Directive.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-APIneeds discussion

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions