dotnet / dotnet/command-line-api

Consider making IValueDescriptor.GetDefaultValue() easier to use with options

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

Description

Hey there! I'm writing some command examples for custom help output, and I had a little difficulty finding the default value for an option from the ParseResult. This is what I ended up with:

```c#
if(((IValueDescriptor)opt).HasDefaultValue)
object? value = ((IValueDescriptor)opt).GetDefaultValue();
```

It would be very helpful I was not required to cast the option, and the method didn't throw an exception if there was no default. In that case, I could get the default value by writing something like:

```c#
object? value = opt.GetDefaultValue();
```

Arguments already make the method and field available. It would still be helpful to have this functionality for options too, even if it isn't possible to get around the exception.

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.