dotnet / dotnet/command-line-api

Type Binding

Open
#2,270 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
C#
Stars
3.7k
Forks
428
PR merge metrics
No merged PRs in 30d

Description

## Current Problems

- We cannot register custom type binding. We have to provide a `parseArgument` method to every option and/or argument where the same custom type is used.

- We cannot leverage the existing validation logic for supported types such as `Uri` to parse custom types, since we are back to dealing with string tokens once we use `parseArgument`.

## Proposed Solution

I would like to have an API that allows custom **type** binding.

```cs
builder.BindArgumentType(str => new DbClient(str));
// or, to leverage existing validation for `Uri`
builder.BindArgumentType(uri => new DbClient(uri));
```

Then we can make the code much more lean and readable when we use the type binding.

```cs
new Option("--from"),

// the following should work even if `List` is not registered by the user
new Option>("--to"),
```

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.