【发布时间】:2016-03-06 17:04:26
【问题描述】:
我有这两个属性:
[Option("IpAddress1")]
public string IpAddress1 { get; set; }
[Option("IpAddress2")]
public string IpAddress2 { get; set; }
当使用这些参数运行时:
--IpAddress1 "1.1.1.1" --IpAddress2" 1.1.1.1"
我收到“MissingValueOptionError”。
运行时:
--IpAddress1 "1.1.1.1" --IpAddress2 "1.1.1.2"
一切正常。
知道为什么吗?
CommandLineParser nuget: https://github.com/gsscoder/commandline
更新1: 看起来它与设置“_.IgnoreUnknownArguments = true;”有关
new Parser(
_ =>
{
_.CaseSensitive = false;
_.HelpWriter = helpWriter;
_.IgnoreUnknownArguments = true;
}).
ParseArguments<T>(commandLineArguments).
WithParsed(_ => parsedFromCommandLineArguments = _).
WithNotParsed(
_ =>
{
parseSucceeded = false;
if (_.Any(
__ => __.Tag == ErrorType.HelpRequestedError ||
__.Tag == ErrorType.HelpVerbRequestedError))
{
isHelpRequestedDetected = true;
}
});
【问题讨论】:
-
语法不应该是
--IpAddress1 "1.1.1.1" --IpAddress2 "1.1.1.2"吗? -
你说得对。我改变了它。它的行为仍然相同。我还尝试了其他字符串(例如“aaa”“aaa”与“aaa”“aab”),它的行为仍然相同。
-
用更具体的东西更新了这个问题。看起来它与设置 IgnoreUnknownArguments 属性有关。
标签: c# command-line command-line-parser