Skip to content

Commit 2557b0c

Browse files
committed
fix #1135
1 parent 34c0c34 commit 2557b0c

File tree

5 files changed

+38
-8
lines changed

5 files changed

+38
-8
lines changed

src/System.CommandLine.Tests/SuggestionTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,7 @@ public void Enum_suggestions_can_be_configured_without_list_clear()
987987
{
988988
var command = new Command("the-command")
989989
{
990-
new Argument<DayOfWeek?>()
990+
new Argument<DayOfWeek?>
991991
{
992992
Suggestions = { "mon", "tues", "wed", "thur", "fri", "sat", "sun" }
993993
}

src/System.CommandLine/Argument.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class Argument : Symbol, IArgument
1919
private IArgumentArity? _arity;
2020
private TryConvertArgument? _convertArguments;
2121
private Type _argumentType = typeof(string);
22-
private List<ISuggestionSource>? _suggestions = null;
22+
private SuggestionSourceList? _suggestions = null;
2323

2424
/// <summary>
2525
/// Initializes a new instance of the Argument class.
@@ -93,13 +93,13 @@ internal TryConvertArgument? ConvertArguments
9393
/// <summary>
9494
/// Gets the list of suggestion sources for the argument.
9595
/// </summary>
96-
public List<ISuggestionSource> Suggestions
96+
public SuggestionSourceList Suggestions
9797
{
9898
get
9999
{
100100
if (_suggestions is null)
101101
{
102-
_suggestions = new List<ISuggestionSource>
102+
_suggestions = new SuggestionSourceList
103103
{
104104
SuggestionSource.ForType(ArgumentType)
105105
};

src/System.CommandLine/Builder/CommandLineBuilderExtensions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
using System.IO;
1111
using System.Linq;
1212
using System.Reflection;
13-
using System.Text;
1413
using System.Threading;
1514
using System.Threading.Tasks;
1615
using static System.Environment;

src/System.CommandLine/SuggestionSourceExtensions.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
// Copyright (c) .NET Foundation and contributors. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4-
using System.Collections.Generic;
54
using System.CommandLine.Suggestions;
65

76
namespace System.CommandLine
87
{
98
public static class SuggestionSourceExtensions
109
{
1110
public static void Add(
12-
this List<ISuggestionSource> suggestionSources,
11+
this SuggestionSourceList suggestionSources,
1312
SuggestDelegate suggest)
1413
{
1514
if (suggestionSources is null)
@@ -26,7 +25,7 @@ public static void Add(
2625
}
2726

2827
public static void Add(
29-
this List<ISuggestionSource> suggestionSources,
28+
this SuggestionSourceList suggestionSources,
3029
params string[] suggestions)
3130
{
3231
if (suggestionSources is null)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// // Copyright (c) .NET Foundation and contributors. All rights reserved.
2+
// // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System.Collections;
5+
using System.Collections.Generic;
6+
using System.CommandLine.Suggestions;
7+
8+
namespace System.CommandLine
9+
{
10+
public class SuggestionSourceList : IReadOnlyList<ISuggestionSource>
11+
{
12+
private readonly List<ISuggestionSource> _sources = new List<ISuggestionSource>();
13+
14+
public void Add(ISuggestionSource source)
15+
{
16+
_sources.Add(source);
17+
}
18+
19+
public IEnumerator<ISuggestionSource> GetEnumerator() => _sources.GetEnumerator();
20+
21+
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
22+
23+
public void Clear()
24+
{
25+
_sources.Clear();
26+
}
27+
28+
public int Count => _sources.Count;
29+
30+
public ISuggestionSource this[int index] => _sources[index];
31+
}
32+
}

0 commit comments

Comments
 (0)