2017-10-16 8 views
0

イムは、コンソールアプリケーションを作成し、それは素晴らしい作品が、それのいくつかの部分がtheresの例を切り替えるために、私はしたいと思い、私はこれをグーグルで試したと私は印刷する場合、これまで、何の結果になっていない可能なすべてのスイッチケースをリストしますか?

case "help": 
    //List all cases here without Console.WriteLine("Option, Option, Option") 

それが返すスイッチの値ヘルプ:/

+0

Mainでは、あなたはデフォルトの 'を求めていますか:'? –

+0

Whartは「Console.WriteLine( "Option、Option、Option")」を除いてここにすべてのケースをリストすることを意味しますか? – Enigmativity

+0

そのおかげで、以下の答えがうまくいきます:) –

答えて

1

CommandLineParserからhttps://commandline.codeplex.com/でこれを達成しました。例えば

class Options 
    { 
     [Option("account-name", Required = true, HelpText = "Name of the account to use")] 
     public string AccountName { get; set; } 

     [Option("single-file", HelpText = "Use one file as output")] 
     public bool SingleFile { get; set; } 

     [Option("excel-timestamps", DefaultValue = false, HelpText = "If set, timestamps will be printed with no timezone information in a format recognisable by Excel")] 
     public bool ExcelTimestamps { get; set; } 

     [ParserState] 
     public IParserState LastParserState { get; set; } 

     [HelpOption] 
     public string GetUsage() 
     { 
      return HelpText.AutoBuild(this, 
       (HelpText current) => HelpText.DefaultParsingErrorsHandler(this, current)); 
     } 
    } 

その後

static int Main(string[] args) 
    { 
     try 
     { 
      var options = new Options(); 
      if (!Parser.Default.ParseArguments(args, options)) 
      { 
       options.GetUsage();//Prints to console 

       (...) 
関連する問題