从 C# 中的命令行自定义主入口点参数
Custom main entry point parameters from the command line in C#
我在网上某处看到有人展示了似乎有效的 C# 代码。它允许将 main 方法中的自定义参数作为命令行参数传递。它看起来像这样:
static void Main(FileInfo input, int maxSize = 9, bool someflag = false)
{
// code
}
这可以像这样在命令行中使用:
$ myApp hello_world.txt --maxSize 10 --someflag
这真的可能吗,还是有人在耍我?
是的,您可以使用 DragonFruit,dotnet CLI 的一个(当前)alpha 功能。
Interpreting the string[]
arguments into behaviors has been left as a task for the developer. Did the user ask for help? Did they pass invalid input? Can the input be converted to the types that you need if they're not string
? These problems are not solved for you.
What if you could declare a strongly-typed Main
method? This was the question that led to the creation of the experimental app model called "DragonFruit", which allows you to create an entry point with multiple parameters of various types and using default values [...]
我在网上某处看到有人展示了似乎有效的 C# 代码。它允许将 main 方法中的自定义参数作为命令行参数传递。它看起来像这样:
static void Main(FileInfo input, int maxSize = 9, bool someflag = false)
{
// code
}
这可以像这样在命令行中使用:
$ myApp hello_world.txt --maxSize 10 --someflag
这真的可能吗,还是有人在耍我?
是的,您可以使用 DragonFruit,dotnet CLI 的一个(当前)alpha 功能。
Interpreting the
string[]
arguments into behaviors has been left as a task for the developer. Did the user ask for help? Did they pass invalid input? Can the input be converted to the types that you need if they're notstring
? These problems are not solved for you.
What if you could declare a strongly-typed
Main
method? This was the question that led to the creation of the experimental app model called "DragonFruit", which allows you to create an entry point with multiple parameters of various types and using default values [...]