Command Line Parser Library - Boolean Parameter

∥☆過路亽.° 提交于 2019-12-01 14:41:05

问题


I try to pass a boolean parameter to a console application and process the value with the Command Line Parser Library.

[Option('c', "closeWindow", Required = true, HelpText = "Close the window.")]
public bool CloseWindow { get; set; }

I tried to pass the parameter as

-c false
-c False
-c "false"
-...

There are no differences, on each try I get "true" as value.

Can anyone tell me how I have to pass the parameter to get the boolean false value?

To avoid possible asks, there is a string option which is passed correctly:

[Option('s', "system", Required = true, HelpText = "Any help text")]
public string System { get; set; }

回答1:


You don't need to add True or False. Using -c will evaluate to True. Not using it will evaluate to False. Somewhere in the documentation there is an example with -v for verbose output. But I can't find it right now. I guess Required=true is not necessary for Boolean options.



来源:https://stackoverflow.com/questions/35873835/command-line-parser-library-boolean-parameter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!