8000 Question: Complex object binding parameter redirection · Issue #1457 · dotnet/command-line-api · GitHub
[go: up one dir, main page]

Skip to content
Question: Complex object binding parameter redirection #1457
Open
@rgn

Description

@rgn

Hi there,

thank you providing such a great library!

I've read through the issues section and came across #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<string>(new string[] { "--some" }, () => default, "Binding assigns value to SomeId."));
complexTypeCommand.Handler = CommandHandler.Create<ComplexType>(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<string>(new string[] { "--some" }, () => default, "Binding assigns value to SomeId."), propertyToBind: nameof(ComplexType.SomeId));

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0