dotnet / dotnet/command-line-api

Question: Complex object binding parameter redirection

Open
#1,457 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
3.7k
Forks
428
PR merge metrics
No merged PRs in 30d

Description

Hi there,

thank you providing such a great library!

I've read through the issues section and came across [#1012](https://github.com/dotnet/command-line-api/pull/1012).

In my scenario, a complex class is used to create the handler. Is there currently any way to *redirect* an option or argument to a property of the complex class **not** matched by name?

I can't use the other binding approach, as I use a generic method (AddItem) to handle the bound complex types.

**Example**

```
public class ComplexType
{
public string SomeId { get; set; }
...
}

...

complexTypeCommand.AddOption(new Option(new string[] { "--some" }, () => default, "Binding assigns value to SomeId."));
complexTypeCommand.Handler = CommandHandler.Create(AddItem);
```

As an idea it might be possible to introduce an additional parameter to AddOption or AddArgument to express an explicit binding.

**Example**
```
complexTypeCommand.AddOption(new Option(new string[] { "--some" }, () => default, "Binding assigns value to SomeId."), propertyToBind: nameof(ComplexType.SomeId));

```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.