gpt4 book ai didi

c# - 如何读取代码中的输出类型

转载 作者:行者123 更新时间:2023-12-02 17:24:24 24 4
gpt4 key购买 nike

我们遇到的一个常见问题是必须根据我们是在本地测试还是为构建服务器提交代码来切换下面的代码。

    /// <summary>
/// Main entry point to the application.
/// </summary>
public static void Main()
{
// Don't forget to uncomment this if committing (!)
//var servicesToRun = new ServiceBase[] {new myservice()};
//ServiceBase.Run(servicesToRun);

// and re-comment this
RunAsConsoleApp();

}

如果有一种方法可以在代码中进行测试来告诉输出类型,即避免所有“哦不,我提交并破坏了构建”的时间浪费,那将非常有用。

        if (IsConsoleApp)
{
Using(var host= new ServiceHost(typeof(myservice))
{
host.Open();
etc....
}
}
else
{
var servicesToRun = new ServiceBase[] {new myservice()};
ServiceBase.Run(servicesToRun);
}

最佳答案

您是否尝试过使用 Environment.UserInteractive属性代替 IsConsoleApp

关于c# - 如何读取代码中的输出类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12915135/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com