You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Double generic types and members with non-generic equivalents #2757
// In addition to these:T?ParseResult.GetValue<T>(Option<T>option);new Option<T>(stringname,paramsstring[]aliases);// etc...// Make it possible to call them like this:object?ParseResult.GetValue(Optionoption,TypevalueType);newOption(TypevalueType,stringname,paramsstring[]aliases);
This is somewhat similar to what we have in DI:
// We can add service like this:services.AddSignleton<T>();// Or this:services.AddSingleton(TypeserviceType);
Justification
I am making my own library that adds proper hosting API, making using System.CommandLine similar to any regular ASP.NET project.
For example:
publicvoidMapCommand(stringname,Delegatecommand){RootCommandrootCommand=[];ParameterInfo[]parameters=command.Method.GetParameters();foreach(ParameterInfoparameterInfoinparameters){if(parameterInfo.GetCustomAttribute<OptionAttribute>()is not null){Optionoption=(typeof(Option<>).MakeGenericType(parameterInfo.ParameterType).GetConstructor([typeof(string),typeof(string[])])!.Invoke([name])asOption)!;rootCommand.Options.Add(option);}}// etc...}
At first glance this looks fine – just make a generic type using reflection. Only the problem is that this is not AOT compatible and will cause exceptions. Adding alternatives that accept types as parameters would solve this.
Additional context
I've glossed over the codebase, and it doesn't look like it will be that hard to implement changes. If that's ok with you, I can prepare a PR myself.
@KalleOlaviNiemitalo yeah, it kinda touches the same topic, but my point is that there should be non-generic API in base implementation regardless of whether to open up protected classes or not. So, I figured this would be better off as a separate issue.
Activity
KalleOlaviNiemitalo commentedon Jan 13, 2026
#1889 is similar.
XFox111 commentedon Jan 13, 2026
@KalleOlaviNiemitalo yeah, it kinda touches the same topic, but my point is that there should be non-generic API in base implementation regardless of whether to open up protected classes or not. So, I figured this would be better off as a separate issue.