[英]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.