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
Not sure if this was the case with the beta-2 but with beta-3 if I want to use my own custom class that implements a default public constructor that takes a single string argument the parsing doesn't works without specifying a parser.
If I use the same code with a Uri Type instead of the TestClass it doesn't require a parser for working.
Is it expected to remove the support for custom class with default string constructor since the changes in beta2/3 ?
Following code works only if I use the Argument creation with a parser:
#r "nuget:System.CommandLine,*-*"usingSystem.CommandLine;usingSystem.CommandLine.Builder;usingSystem.CommandLine.Invocation;usingSystem.CommandLine.Parsing;classTestClass{publicTestClass(stringvalue){Value=value;}publicstringValue{get;privateset;}}staticTestClassParseTestClass(ArgumentResultresult){if(result.Tokens.Count==1)returnnewTestClass(result.Tokens[0].Value);result.ErrorMessage=$"Not a unique argument";returndefault;}// Not working using default public constructorvarargTestClass=newArgument<TestClass>("TC");// Working using a parser// var argTestClass = new Argument<TestClass>("TC", ParseTestClass);varargString=newArgument<string>("string");varcmd=newRootCommand("root"){argTestClass,argString};cmd.SetHandler<TestClass,string>((tc,s)=>{Console.WriteLine($"TestClass: {tc.Value}, string: {s}");},argTestClass,argString);varparser=newCommandLineBuilder(cmd).Build();parser.Invoke("Hello World");
The text was updated successfully, but these errors were encountered:
This was a deliberate change in order to reduce the use of reflection and support trimming.
We plan to support this kind of convention via source generators in the future, or you can get the old behavior (via CommandHandler.Create) by referencing System.CommandLine.NamingConventionBinder.
Dear All,
Not sure if this was the case with the beta-2 but with beta-3 if I want to use my own custom class that implements a default public constructor that takes a single string argument the parsing doesn't works without specifying a parser.
If I use the same code with a Uri Type instead of the TestClass it doesn't require a parser for working.
Is it expected to remove the support for custom class with default string constructor since the changes in beta2/3 ?
Following code works only if I use the
Argument
creation with a parser:The text was updated successfully, but these errors were encountered: