|
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Xml.Linq;
- using Advantech.Motion;
- using Newtonsoft.Json;
- using Newtonsoft.Json.Serialization;
- using AssistClient.UI.PropExtend;
- using static AssistClient.UI.UIAxisDev;
-
- namespace AssistClient.UI
- {
- //[TypeConverter(typeof(PropertySorter))] //此属性使类无法序列化和反序列化
- public class ForProp
- {
- [PropertyOrder(11), Browsable(false), Category("1 标识"), DisplayName("1.1 标识"), Description("标识"), ReadOnly(true)]
- public long UniqueId { get; set; } = DateTime.Now.Ticks;
- [PropertyOrder(11), Browsable(true), Category("1 控制"), DisplayName("1.1 跳转步骤"), Description("跳转步骤 1-n")]
- public int GotoStepIndex { get; set; } = 1;
-
- [PropertyOrder(12), Browsable(true), Category("1 控制"), DisplayName("1.2 循环次数"), Description("循环次数 1-n")]
- public int LimitNum { get; set; } = 1;
-
- [PropertyOrder(25), Browsable(true), Category("1 控制"), DisplayName("1.3 是否重置"), Description("达到循环次数后是否置0")]
- public bool Reset { get; set; }
- [PropertyOrder(27), Browsable(true), Category("1 控制"), DisplayName("1.4 禁用工序"), Description("禁用本工序")]
- public bool Disable { get; set; }
- /// <summary>
- /// 序列化
- /// </summary>
- /// <param name="obj"></param>
- /// <returns></returns>
- public string serialize()
- {
- return JsonConvert.SerializeObject(this);
- }
- /// <summary>
- /// 反序列化
- /// </summary>
- /// <param name="json"></param>
- /// <returns></returns>
- public void deserialize(string json)
- {
- var o= JsonConvert.DeserializeObject<ForProp>(json);
- Type type = o.GetType();
- System.Reflection.PropertyInfo[] properties = type.GetProperties();
- foreach (System.Reflection.PropertyInfo property in properties)
- {
- string name = property.Name;
- if (!type.GetProperty(name).IsDefined(typeof(JsonIgnoreAttribute), true))
- {
- var value = property.GetValue(o);
- this.GetType().GetProperty(name).SetValue(this, value);
- }
- }
- }
- }
-
-
- }
|