我如何使用CommandLine.Parser来支持这一点?
program.exe -s file1 -t file2 -t file3
是的。这是可能的IEnumerable
:
class Program
{
static void Main(string[] args)
{
args = new[] { "-s", "sourceFile", "-t", "targetFile1", "targetFile2" };
Parser.Default.ParseArguments<MyOptions>(args).WithParsed(o =>
{
foreach (var target in o.Targets)
{
Console.WriteLine(target);
}
});
Console.ReadKey();
}
}
internal class MyOptions
{
[Option('s')]
public string Source { get; set; }
[Option('t')]
public IEnumerable<string> Targets { get; set; }
}
很酷的是,你甚至可以使用andFileInfo
属性。DirectoryInfo
CommandLine.Option