由code设置默认的调试命令行参数?命令行、参数、code

2023-09-06 15:51:20 作者:拥你久伴

有一种方法来设置默认的调试命令行参数或默认应用程序参数没有设置的参数中的项目设置调试选项卡?

我的意思是,如果我可以做这样的事情:

 模块主要

#如果DEBUG然后,
  我的应用程序的调试命令行参数:
  My.Application.CommandLineArgs = - 睡眠5 -interval 50 -Key CTRL + C
#END如果

...子的main()
   GetArguments()函数获取至极,我已经设置arguemnts。
...等等...

前端模块
 

解决方案 VScode下Python程序接收命令行参数的运行和调试

您可以创建一个类,将抽象的其他code命令行。为了调试编译它​​将返回固定的字符串,否则将返回真正的Enviroment.CommandLine。

 公共静态类CommandLineHelper
{
  公共静态字符串GetCommandLine()
  {
   #如果调试
     回到我的命令行字符串;
   #其他
     返回Enviroment.CommandLine;
   #ENDIF
  }
}
 

There is a way to set the default debug commandline arguments or the default application arguments without setting the arguments in the Debug tab of the project settings?

I'll mean if I can do something like this:

Module Main

#If DEBUG Then
  ' Debug Commandline arguments for my application:
  My.Application.CommandLineArgs = "-Sleep 5 -Interval 50 -Key CTRL+C"
#End If

...Sub main()
   GetArguments() ' A function wich gets the arguemnts that I've set.
...etc...

End module

解决方案

You can create a class that will abstract your other code from command line. For debug compilation it will return fixed string, otherwise it will return real Enviroment.CommandLine.

public static class CommandLineHelper
{
  public static string GetCommandLine()
  {
   #if DEBUG
     return "my command line string";
   #else
     return Enviroment.CommandLine;
   #endif
  }
}