Command Line Parser Library - Boolean Parameter

前端 未结 2 1212
独厮守ぢ
独厮守ぢ 2021-01-03 20:34

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

[Option(\'c\', \"closeWindow\", Requir         


        
2条回答
  •  时光取名叫无心
    2021-01-03 21:18

    bool? behaves the way you want

    with :

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

    the result will be :

    -c false // -> false
    -c true  // -> true
    -c       // -> error
             // -> error if Required = true, null otherwise
    

提交回复
热议问题