private void Button1_Click(object sender, EventArgs e) { IUIControlsFactory factory = null; switch ((UIControls)this.cbOSControls.SelectedIndex) { case UIControls.cLinux: factory = new LinuxUIFactory(); break; case UIControls.cWindows: factory = new WindowsUIFactory(); break; default: MessageBox.Show("Не сте избрали OS за UI контролите!"); return; } IUIControl button = factory.getButton(); IUIControl textbox = factory.getTextBox(); IUIControl combobox = factory.getComboBox(); IUIControl label = factory.getLabel(); this.tbUIControls.Clear(); this.tbUIControls.AppendText("Button type: " + button.getName() + Environment.NewLine); this.tbUIControls.AppendText("ComboBox type: " + combobox.getName() + Environment.NewLine); this.tbUIControls.AppendText("TextBox type: " + textbox.getName() + Environment.NewLine); this.tbUIControls.AppendText("Label type: " + label.getName() + Environment.NewLine); }
private static void Main(string[] args) { UIFactory uiFactory = null; if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { Console.WriteLine("Sorry, program does not contain UI system for Linus OS for now. Keep trying."); return; } if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { uiFactory = new WindowsUIFactory(); } else if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { uiFactory = new MacUIFactory(); } Console.WriteLine($"UI is built on top of {uiFactory} respectively to OS where you run this program."); }