推薦一個.NET 命令列參數Parser 庫

來源:互聯網
上載者:User

Command Line Parser Library 是個很簡潔方便的 命令參數解析的類庫,代碼也不多,只兩個cs檔案,但功能一點也不少.
先看下QuickStart:

Test.exe, Program.cs:

class Options  {      [Option("d", "debug", DefaultValue = false, HelpText = "Debug Mode.")]      public bool Debug { get; set; }      [Option("h", "help", DefaultValue = false, HelpText = "Show Help")]      public bool ShowHelp { get; set; }      [HelpOption]      public string GetUsage()      {          var usage = new StringBuilder();          usage.AppendLine("Use -d or -debug to Debug");          return usage.ToString();      }  }  class Program  {      static void Main(string[] args)      {          var options = new Options();          CommandLineParser.Default.ParseArguments(args, options);          if (options.ShowHelp)          {              Console.WriteLine(options.GetUsage());              return;          }          if (options.Debug)          {              Console.WriteLine("debug");          }       }  }

其中,d參數是debug的全稱,可以使用-d或者-debug.並可以指定預設值

測試:

Test.exe –d

Test.exe –h  顯示使用協助資訊

除了簡單的參數外,還支援列表參數,數組等,詳細的用法,參照:

http://commandline.codeplex.com/documentation

現在這個程式碼程式庫已遷移到GitHub. Git現在越來越紅了,連Codeplex現在也開始支援Git了

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.