dotnet / dotnet/command-line-api
can SymbolResult.ArgumentConversionResult be made public?
- Dominant language
- C#
- Stars
- 3.7k
- Forks
- 428
- PR merge metrics
- No merged PRs in 30d
Description
I am mapping my MediatR requests to console commands and am wondering why the System.CommandLine.Binding.SuccessfulArgumentConversionResult was made internal and also if the SymbolResult.ArgumentConversionResult could be made public.
I am currently using reflection to access these values (see below) and was wondering what harm it would be in exposing them.
```csharp
public async Task InvokeAsync(InvocationContext aInvocationContext)
{
try
{
var request = (IRequest)Activator.CreateInstance(Type);
foreach (SymbolResult symbolResult in aInvocationContext.ParseResult.CommandResult.Children)
{
Type optionResultType = typeof(OptionResult);
object theArgumentConversionResult =
optionResultType.GetProperty("ArgumentConversionResult", BindingFlags.NonPublic | BindingFlags.Instance)
?.GetValue(symbolResult);
Type successfulArgumentConversionResultType =
optionResultType.Assembly.GetType("System.CommandLine.Binding.SuccessfulArgumentConversionResult");
object theValue =
successfulArgumentConversionResultType.GetProperty("Value")?.GetValue(theArgumentConversionResult);
Type.GetProperty(symbolResult.Symbol.Name).SetValue(request, theValue); // "Haa",9,7,"Ha"
}
await Mediator.Send(request);
return 0;
}
catch (Exception excpetion)
{
Console.Error.WriteLine(excpetion.Message);
return 1;
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.