将 C# 命令行解析器选项的值限制为整数

Restrict values of C# command-line-parser options to Integers

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

类型的值

我已经通读了图书馆的文档,但没有找到这样的功能。但也许我错过了什么。

感谢您的帮助!

显然您所要做的就是将 return 类型声明为 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