-
Notifications
You must be signed in to change notification settings - Fork 481
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Value not available after Pasring #107
Comments
Comment by LtKlaus I'm trying to figure out the same thing. I'm using v2.1.1-beta. I'm trying to create a program that will support different commands. I'm using ParseArguments and passing in the possible types using the options classes I created. A simple example is below. When I run this in the debugger I can see that parserResults has a property called Value and it's of type SecondCommandOptions. When typing out the code, there's no Value property on the parserResults object. How can I get the Value from parserResults so I can get it's type and cast it to the appropriate options class?
|
Comment by LtKlaus I was able to get Value using Reflection and was able to cast it to my options classes. I'm not sure why the Value property isn't accessible without using Reflection.
|
Comment by LtKlaus Actually Reflection isn't needed and I realized why. I wasn't paying attention to the return value from ParseArguments which is ParserResult< object > and that can cast to Parsed< object > or NotParsed< object >. I just needed to parse it to Parsed< object > then I could access Value and could then check the type of Value and cast it to the appropriate options class. Hope this will help someone else figure this out quicker than I did. Spent more time scratching my head than I would like to admit.
|
Comment by LtKlaus @nemec Thanks. I just had a look at those methods and gave them a quick test. They do the conversion for me but with the drawback of not being able to return a value. My current method that processes the Value will return the command that's associated with the options class that was created. I'd have to make a few changes in my code to handle the commands differently but it's do able and worth a look. |
The [Pr #634) exposes the Parsed option Value to the base class, available in develop branch and will be released in v2.9. var result = Parser.Default.ParseArguments<Options>(args);
Options options = result.Value; |
Issue by dpparekh
Wednesday Jan 18, 2017 at 20:04 GMT
Originally opened as gsscoder/commandline#405
I am doing the following thing in my code but there is a compile time error that Value isn't part of result.
What am I missing?
The text was updated successfully, but these errors were encountered: