繁体   English   中英

如何在C#中使用Factory模式来选择我想要的GUI:WPF或控制台?

[英]How to make Factory pattern in c# to choose which GUI i want : WPF or Console?

我做一个计算器程序。 我做了四个项目。

  1. 具有计算器逻辑的类库。
  2. WPF应用程序中的计算器GUI。
  3. 控制台应用程序中的计算器gui。
  4. 工厂类库,即“启动项目”。

GUI应用程序(WPF或控制台)效果很好! 他们在其依赖项中具有“逻辑类库”。

现在,我想从我的客户那里选择他想要的GUI,因此我为他编写了Factory类库并将其设置为“启动项目”。

但这是行不通的,因为错误消息“类库无法直接启动”。

该怎么办?

谢谢你。

类库不能是启动项目。 它必须是exe,而不是dll。

我要做的是:

  • 创建类似start.bat之类的内容,询问用户他想要哪个gui版本。 然后批处理将运行wpf.exe或console.exe

要么

  • 创建将执行相同操作的简单控制台应用程序。 启动exec后,它将关闭。

控制台应用程序或批处理程序可能还会读取某些注册表项,并基于该调用适当的exec。

最简单的方法是创建另一个应用程序,它的唯一任务是启动GUI版本或CLI版本。

您可以在专用的console application执行此操作,但是稍后您会看到console box弹出窗口。

或者,您可以使用WinForms应用程序并使用以下代码行:

using System.Diagnostics;

static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main(string [] args)
    {
        // disable these lines:
        //Application.EnableVisualStyles();
        //Application.SetCompatibleTextRenderingDefault(false);
        //Application.Run(new Form1());

        //read settings file or parse arguments

        //start the GUI or CLI process
        Process process = new Process();
        process.StartInfo.FileName = "some.exe";
        process.Start();
        //optional
        process.WaitForExit();
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM