Skip to content

Make .Values read-only on CommandArgument/Option#406

Merged
natemcmaster merged 1 commit intorelease/4.0from
feature/api-cleanup
Nov 7, 2020
Merged

Make .Values read-only on CommandArgument/Option#406
natemcmaster merged 1 commit intorelease/4.0from
feature/api-cleanup

Conversation

@natemcmaster
Copy link
Owner

@natemcmaster natemcmaster commented Nov 7, 2020

Exposing a raw List of values on CommandArgument and
CommandOption has made it difficult to cleanly implement features like
default values or parsing. This changes the return type of .Values to a
read-only list, and adds TryParse for adding new values, and Reset for
clearing them.

Upgrading

Before

var myOption = new CommandOption("--abc <ABC>", CommandOptionType.MultipleValue);
myOption.Values.Add("xyz");
myOption.Values.AddRange(new [] { "xyz", "123" });
myOption.Values.Clear();

var myArg = new CommandArgument("ABC");
myArg.Values.Add("xyz");
myArg.Values.AddRange(new [] { "xyz", "123" });
myArg.Values.Clear();

After

var myOption = new CommandOption("--abc <ABC>", CommandOptionType.MultipleValue);
myOption.TryParse("xyz");  // note! You should check to see the return type on `TryParse` as it might be values if this value was not accepted.
foreach (var v in new [] { "xyz", "123" })
   myOption.TryParse(v);
myOption.Reset();

var myArg = new CommandArgument("ABC");
myArg.TryParse("xyz");  // note! You should check to see the return type on `TryParse` as it might be values if this value was not accepted.
foreach (var v in new [] { "xyz", "123" })
   myArg.TryParse(v);
myArg.Reset();

Exposing a raw List<string> of values on CommandArgument and
CommandOption has made it difficult to cleanly implement features like
default values or parsing. This changes the return type of .Values to a
read-only list, and adds TryParse for adding new values, and Reset for
clearing them.
@natemcmaster natemcmaster added this to the 4.0.0 milestone Nov 7, 2020
@natemcmaster natemcmaster merged commit 6968682 into release/4.0 Nov 7, 2020
@natemcmaster natemcmaster deleted the feature/api-cleanup branch November 7, 2020 23:26
natemcmaster added a commit that referenced this pull request Jan 10, 2021
Exposing a raw List<string> of values on CommandArgument and
CommandOption has made it difficult to cleanly implement features like
default values or parsing. This changes the return type of .Values to a
read-only list, and adds TryParse for adding new values, and Reset for
clearing them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant