2017-10-16 74 views
0

林做一個控制檯應用程序和它的作品很好,但對於它的某些部分孤單切換的情況下,我想作一個列出所有可能的開關情況?

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

我曾試着用搜索引擎這也是迄今爲止轉身沒有結果,如果我打印它返回的交換機的值幫助:/

+0

你要求'默認:'? –

+0

Whart的意思是「在這裏列出所有情況下沒有Console.WriteLine(」選項,選項,選項「)」? – Enigmativity

+0

其好兄弟下面的答案工作正常:) –

回答

1

我已經實現了CommandLineParserhttps://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)); 
     } 
    } 

然後在Main

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

       (...)