[英]How to make Factory pattern in c# to choose which GUI i want : WPF or Console?
我做一个计算器程序。 我做了四个项目。
GUI应用程序(WPF或控制台)效果很好! 他们在其依赖项中具有“逻辑类库”。
现在,我想从我的客户那里选择他想要的GUI,因此我为他编写了Factory类库并将其设置为“启动项目”。
但这是行不通的,因为错误消息“类库无法直接启动”。
该怎么办?
谢谢你。
类库不能是启动项目。 它必须是exe,而不是dll。
我要做的是:
要么
控制台应用程序或批处理程序可能还会读取某些注册表项,并基于该调用适当的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.