[英]How to make Factory pattern in c# to choose which GUI i want : WPF or Console?
I make a calculator program. 我做一个计算器程序。 I made four projects. 我做了四个项目。
The GUI applications (WPF or Console) works great! GUI应用程序(WPF或控制台)效果很好! they have the "logic class library" in their dependencies. 他们在其依赖项中具有“逻辑类库”。
Now i want from my client to choose which GUI he wants, so i wrote for him Factory class library and make it "startup project". 现在,我想从我的客户那里选择他想要的GUI,因此我为他编写了Factory类库并将其设置为“启动项目”。
But it doesn't work because the error message "class library cannot be started directly". 但这是行不通的,因为错误消息“类库无法直接启动”。
What to do? 该怎么办?
thanks in ahead. 谢谢你。
Class library cannot be startup project. 类库不能是启动项目。 It must be exe, not dll. 它必须是exe,而不是dll。
What I would do is: 我要做的是:
or 要么
Console app or batch may also read some registry entry and based on that call apropriate exec. 控制台应用程序或批处理程序可能还会读取某些注册表项,并基于该调用适当的exec。
The easiest way is to create another application which it's only task is to start either the GUI version or the CLI version. 最简单的方法是创建另一个应用程序,它的唯一任务是启动GUI版本或CLI版本。
You could do this in a dedicated console application
, but then you'll see the console box
popup for a small second. 您可以在专用的console application
执行此操作,但是稍后您会看到console box
弹出窗口。
As alternative you could use a WinForms
application and use the folowing lines of code: 或者,您可以使用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.