Skip to content

Commit

Permalink
make SymbolSet an IReadOnlyList<Symbol>
Browse files Browse the repository at this point in the history
  • Loading branch information
jonsequitur committed Jan 7, 2022
1 parent d4cae87 commit d00241c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ System.CommandLine.Builder
public static CommandLineBuilder UseVersionOption(this CommandLineBuilder builder)
public static CommandLineBuilder UseVersionOption(this CommandLineBuilder builder, System.String[] aliases)
System.CommandLine.Collections
public class SymbolSet, System.Collections.Generic.IEnumerable<System.CommandLine.Symbol>, System.Collections.IEnumerable
public class SymbolSet, System.Collections.Generic.IEnumerable<System.CommandLine.Symbol>, System.Collections.Generic.IReadOnlyCollection<System.CommandLine.Symbol>, System.Collections.Generic.IReadOnlyList<System.CommandLine.Symbol>, System.Collections.IEnumerable
.ctor()
public System.Int32 Count { get; }
public System.CommandLine.Symbol Item { get; }
Expand Down
7 changes: 5 additions & 2 deletions src/System.CommandLine/Collections/SymbolSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ namespace System.CommandLine.Collections
/// <summary>
/// A set of symbols, unique and indexed by their aliases.
/// </summary>
public class SymbolSet : IEnumerable<Symbol>
public class SymbolSet : IReadOnlyList<Symbol>
{
private readonly List<Symbol> _symbols = new List<Symbol>();
private readonly List<Symbol> _symbols = new();
private List<Argument>? _arguments;
private List<Option>? _options;

/// <inheritdoc />
public int Count => _symbols.Count;

/// <inheritdoc />
public Symbol this[int index] => _symbols[index];

private void ResetIndex(Symbol item)
Expand All @@ -42,6 +44,7 @@ internal void AddWithoutAliasCollisionCheck(Symbol item)
}
}

/// <inheritdoc />
public IEnumerator<Symbol> GetEnumerator() => _symbols.GetEnumerator();

IEnumerator IEnumerable.GetEnumerator() => _symbols.GetEnumerator();
Expand Down

0 comments on commit d00241c

Please sign in to comment.