public void HandleComponentProperties() { const BindingFlags flags = BindingFlags.Public | BindingFlags.Instance; FieldInfo[] fields = SelectedComponent.GetType().GetFields(flags); PropertyInfo[] properties = SelectedComponent.GetType().GetProperties(flags); int numFields = fields.Length + properties.Length; VariableOptionStrings = new string[numFields]; TypesOfVariableOptions = new Type[numFields]; for (int i = 0; i < numFields; i++) { if (i < fields.Length) { TypesOfVariableOptions[i] = fields[i].FieldType; VariableOptionStrings[i] = fields[i].Name; } else { TypesOfVariableOptions[i] = properties[i - fields.Length].PropertyType; VariableOptionStrings[i] = properties[i - fields.Length].Name; } } }
private void AddItem() { if (CheckNumbers() && SelectedComponent != null) { var type = ""; if (SelectedComponent.GetType().Name.Equals("MotherBoard")) { type = "Motherboard"; } else { type = SelectedComponent.GetType().Name; } StockComponent component = new StockComponent { Count = Int32.Parse(Count), PhysicalLocation = Location, Type = type }; Component cmp = SelectedComponent; cmp.Id = new Guid(); component.M_Component = cmp; ConnectionService.Instance.proxy.AddComponent(cmp); component.Id = new Guid(); RuntimeContext.addedStockComponent = ConnectionService.Instance.proxy.AddStockComponent(component); RuntimeContext.msgLabel = "New stock item added to db."; RuntimeContext.commands.Add("added"); LogService.Instance.LogInformation("New stock component added to db."); MainWindowViewModel.Instance.OnNav("data"); } else { LogService.Instance.LogError("Wrong parameters."); MsgLabel = "Wrong number input."; return; } }