dotnet / dotnet/command-line-api
Consider making IValueDescriptor.GetDefaultValue() easier to use with options
- 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
Assessment
This issue has not been assessed yet.