C# 相当于 Perl 的 Getopt::Long
C# equivalent to Perl's Getopt::Long
我正在将一些旧的 Perl 脚本转换为 C#,我需要保持功能基本相同。为此,我需要像 Perl 的 Getopt::Long 一样解析命令行,但我很难弄清楚如何执行此操作。如果有人能让我知道这样做的好方法或指出一个好的参考方向,我将不胜感激。
Jonathon Pryor 写 mono.Options 的动机与他的博客 post 中的相同:http://www.jprl.com/Blog/archive/development/mono/2008/Jan-07.html
我已经在几个项目中使用过它,保留所有的归属注释,并将文件扔到我的项目目录中。非常适合我。
这是我在使用它:
string iniFilePath = null;
OptionSet os = new OptionSet()
{ { "ini="
, "Valid path to an ini file."
, (s) => { iniFilePath = s; }
} };
List<string> extra;
try {
extra = os.Parse( Application.CommandLineArguments );
return iniFilePath;
}
catch ( OptionException oex ) {
Library.ExceptionHandler.handle( oex );
}
return null;
我正在将一些旧的 Perl 脚本转换为 C#,我需要保持功能基本相同。为此,我需要像 Perl 的 Getopt::Long 一样解析命令行,但我很难弄清楚如何执行此操作。如果有人能让我知道这样做的好方法或指出一个好的参考方向,我将不胜感激。
Jonathon Pryor 写 mono.Options 的动机与他的博客 post 中的相同:http://www.jprl.com/Blog/archive/development/mono/2008/Jan-07.html
我已经在几个项目中使用过它,保留所有的归属注释,并将文件扔到我的项目目录中。非常适合我。
这是我在使用它:
string iniFilePath = null;
OptionSet os = new OptionSet()
{ { "ini="
, "Valid path to an ini file."
, (s) => { iniFilePath = s; }
} };
List<string> extra;
try {
extra = os.Parse( Application.CommandLineArguments );
return iniFilePath;
}
catch ( OptionException oex ) {
Library.ExceptionHandler.handle( oex );
}
return null;