[英]Not able to pass text file(.txt) as command line argument to console application
[英]Read (unnamed) argument in console line
由於ConsoleFx的執行速度似乎太慢(糟糕,它有很大的潛力),並且每次構建都顯示太多重大更改,因此我決定切換到Mono.Options來滿足命令行解析的需要。
我的OptionSet是通過以下方法構建的
private static OptionSet BuildOptionSet()
{
OptionSet optionSet = new OptionSet()
.Add("?|help|h", "Prints out the options", option => help = option != null)
.Add("w|wait", "Waits for any key after finished processing", option => wait)
return optionSet;
}
我找到的所有教程都涉及選項以及如何捕獲它們,但從未提及過參數。
以下電話為例
c:\>test.exe brandCode1 brandCode2 /w
應該等待true,然后給我兩個參數,分別是brandCode1和brandCode2。 如何從args []中以干凈的方式捕獲它們?
Mono.Options無法做到這一點嗎?
從我閱讀文檔可以看出,您有時需要調用OptionSet
的parse
方法。 完成后,它將處理您的操作並返回“包含所有未處理參數的List<string>
”。
不幸的是,您還需要向它傳遞main方法的參數才能使它起作用。
List<string> extra = optionSet.Parse(args);
編輯:如果我的鏈接(仍然)不起作用,則解析應鏈接到http://www.ndesk.org/doc/ndesk-options/NDesk.Options/OptionSet.html#M:NDesk.Options.OptionSet。解析%28System.String,NDesk.Options.OptionContext%29
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.