【问题标题】:Restrict values of C# command-line-parser options to Integers将 C# 命令行解析器选项的值限制为整数
【发布时间】:2016-01-22 11:37:49
【问题描述】:

我目前正在开发一个使用此command line parser library 的控制台应用程序。 我的一些选项值应该是整数。所以我想知道是否有办法指定这些选项,使它们只接受 int 类型的值。

我已经阅读了图书馆的纪录片,但没有找到这样的功能。但也许我错过了什么。

感谢您的帮助!

【问题讨论】:

    标签: c# command-line command-line-parser


    【解决方案1】:

    显然,您所要做的就是将返回类型声明为 int。此示例在文档中:

    [Option("l", "length", HelpText = "The maximum number of bytes to process.")]
      public int MaximumLength { get; set; };
    // ...
    }
    
    The following will be accepted.
      GuideApp --length=99
      GuideApp -l12345
      GuideApp -l 555
    The following will be rejected.
      GuideApp --length=a-string
      GuideApp -lsome_text
      GuideApp -l text.again
    

    【讨论】:

    • 谢谢!这正是我想要的:)
    猜你喜欢
    • 2012-12-13
    • 2014-03-11
    • 2017-08-31
    • 2022-01-11
    • 2013-05-16
    • 2011-03-20
    • 2015-01-15
    • 2015-02-28
    • 2016-07-05
    相关资源
    最近更新 更多