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

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

Merged
merged 1 commit into from Nov 7, 2020

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.

None yet

1 participant