コード例 #1
0
        private void LoadData()
        {
            var type = fanuc.CurMacroBom.GetType();

            foreach (PropertyInfo item in type.GetProperties())
            {
                var attributes = item.GetCustomAttribute <DisplayAttribute>();

                if (attributes != null && (attributes.GetAutoGenerateField() ?? true))
                {
                    var limit = item.GetValue(fanuc.CurMacroBom) as MacroBomItem;
                    if (limit == null)
                    {
                        continue;
                    }
                    var node = new SystemMacroItemViewModel()
                    {
                        PropertyName = item.Name,
                        Title        = attributes.Name,
                        Address      = limit?.Adr ?? 0
                    };
                    node.ShowDialogEvent += Node_ShowDialogEvent;
                    MacroNodes.Add(node);
                }
            }
        }
コード例 #2
0
        private void SaveConfig()
        {
            var type = fanuc.CurMacroBom.GetType();

            foreach (PropertyInfo item in type.GetProperties())
            {
                var limit = item.GetValue(fanuc.CurMacroBom) as MacroBomItem;
                if (limit == null)
                {
                    limit = new MacroBomItem();
                    item.SetValue(fanuc.CurMacroBom, limit);
                }
                var prop = MacroNodes.FirstOrDefault(d => d.PropertyName == item.Name);
                if (prop != null)
                {
                    limit.Adr = prop.Address;
                }
            }
            var jsonLimitBom = JsonConvert.SerializeObject(fanuc.CurMacroBom, Formatting.Indented);

            using (StreamWriter sw = new StreamWriter(@"macrobom.cfg", false))
            {
                sw.Write(jsonLimitBom);
            }
        }