入力にフラグが関連付けられていないことを示す「<>」入力を使用できます。オプションは左から右に読み取られるため、開始フラグが検出されたときに「currentParameter」フラグを設定し、フラグのない後続の入力がリストの一部であると想定できます。入力ファイルとしてリストを指定し、キーと値のペアのリストであるディクショナリ (パラメーター) を指定できる例を次に示します。もちろん他のバリエーションもご用意しております。
OptionSet options = new OptionSet()
{
{"f|file", "a list of files" , v => {
currentParameter = "f";
}},
{"p", @"Parameter values to use for variable resolution in the xml - use the form 'Name=Value'. a ':' or ';' may be used in place of the equals sign", v => {
currentParameter = "p";
}},
{ "<>", v => {
switch(currentParameter) {
case "p":
string[] items = v.Split(new[]{'=', ':', ';'}, 2);
Parameters.Add(items[0], items[1]);
break;
case "f":
Files.Add(Path.Combine(Environment.CurrentDirectory, v));
break;
}
}}
};
options.Parse(args);