Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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