Skip to content

Added return statement to add methods to use them as chain method. #1662

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

Closed
wants to merge 1 commit into from
Closed

Conversation

efeerdogru
Copy link

This change is about using add methods as chain methods.

Instead of using like this;

var cmd1 = new Command("cmd1", "Test 1 command.");
cmd1.AddOption(new Option("-o"));

var cmd2 = new Command("cmd2", "Test 2 command.")
{
    cmd1
};

This would be much simplier.

var cmd2 = new Command("cmd2", "Test 2 command.")
{
    new Command("cmd1", "Test 1 command.").AddOption(new Option("-o"))
};

Thanks.

@KalleOlaviNiemitalo
Copy link

Since #1989, the options and arguments can be added using C# initialiser list syntax:

var cmd2 = new Command("cmd2", "Test 2 command.")
{
    new Command("cmd1", "Test 1 command.")
    {
        new Option("-o"),
    },
};

Because "Builder types are the only types in BCL that are allowed to use fluent APIs (returning reference to this to allow for calls chaining)" according to #2057 (comment), I don't believe Add will be changed to return other than void.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants