dotnet / dotnet/command-line-api
Question: Complex object binding parameter redirection
- 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
Assessment
This issue has not been assessed yet.