CommandLine.dll可以从http://commandline.codeplex.com/下载
//选项类
class Options
{
[Option('n', HelpText = "This is a test")]
public string No { get; set; }
[Option('m', HelpText = "This is a test")]
public string Name { get; set; }
[Option('i', HelpText = "This is a test",Required=true)]
public int Id { get; set; }
[Option('f', HelpText = "This is a test")]
public bool Flag { get; set; }
[ParserState]
public IParserState LastParserState { get; set; }
[HelpOption]
public string GetUsage()
{
return HelpText.AutoBuild(this,
(HelpText current) => HelpText.DefaultParsingErrorsHandler(this, current));
}
}
main:
static void Main(string[] args)
{
try
{
//获取main参数
Options option = new Options();
if (CommandLine.Parser.Default.ParseArguments(args, option))
{
if (option.No.Equals(1))
{
//处理
}
if(option.Flag )
{
//处理
}
}
}
}