private void LoadData() { var type = fanuc.CurPmcBom.GetType(); foreach (PropertyInfo item in type.GetProperties()) { var attributes = item.GetCustomAttribute <DisplayAttribute>(); if (attributes != null && (attributes.GetAutoGenerateField() ?? true)) { var limit = item.GetValue(fanuc.CurPmcBom) as PmcBomItem; if (limit == null) { continue; } var node = new SystemPmcItemViewModel() { PropertyName = item.Name, Title = attributes.Name, Adr = limit.Adr, Bit = limit.Bit, ConversionFactor = limit.ConversionFactor ?? 0.0, DataType = limit.DataType }; node.OpenDialogEvent += Node_OpenDialogEvent; PmcNodes.Add(node); } } }
private void SaveConfig() { var type = fanuc.CurPmcBom.GetType(); foreach (PropertyInfo item in type.GetProperties()) { var limit = item.GetValue(fanuc.CurPmcBom) as PmcBomItem; if (limit == null) { limit = new PmcBomItem(); item.SetValue(fanuc.CurPmcBom, limit); } var prop = PmcNodes.FirstOrDefault(d => d.PropertyName == item.Name); if (prop != null) { limit.Adr = prop.Adr; limit.ConversionFactor = prop.ConversionFactor; limit.Bit = prop.Bit; } } var jsonLimitBom = JsonConvert.SerializeObject(fanuc.CurPmcBom, Formatting.Indented); using (StreamWriter sw = new StreamWriter(@"pmcbom.cfg", false)) { sw.Write(jsonLimitBom); } }