/// <summary> /// 获取可以添加的设备 /// </summary> /// <returns></returns> public static List <DevicesInformation> GetCanAddDevices() { Assembly ass = Assembly.GetExecutingAssembly(); Type[] types = ass.GetTypes(); Type[] paramTypes = new Type[] { typeof(string) }; List <DevicesInformation> list = new List <DevicesInformation>(); foreach (var item in types) { if (item.IsClass && !item.IsAbstract && item.GetInterface("Devices.IDevices") != null) { DevicesInformation info = ((IDevices)item.GetConstructor(paramTypes).Invoke(new object[] { null })).Info; info.ClassInfo = item.FullName; list.Add(info); } } return(list); }
private void button1_Click(object sender, EventArgs e) { //DevicesInformation info = comboBox1.SelectedValue as DevicesInformation; TreeValue tree = this.treeComboBox1.SelectedItem as TreeValue; DevicesInformation info = tree?.Value as DevicesInformation; if (info == null) { return; } IDevices newDev = Devices.DevicesCollection.CreateDevices(null, info.ClassInfo); if (newDev.ShowConfigForm() == DialogResult.OK) { if (addedDevs == null) { addedDevs = new List <IDevices>(); } DevicesCollection.Add(newDev); newDev.CommandCompleted += DevicesCollection.commandCompleted; newDev.StateChanged += DevicesCollection.stateChanged; ListViewAddItem(newDev); } }