版博士V2.0程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

64 行
2.5 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Xml.Linq;
  8. using Advantech.Motion;
  9. using Newtonsoft.Json;
  10. using Newtonsoft.Json.Serialization;
  11. using ProductionControl.UI.PropExtend;
  12. using static ProductionControl.UI.UIAxisDev;
  13. namespace ProductionControl.UI
  14. {
  15. //[TypeConverter(typeof(PropertySorter))] //此属性使类无法序列化和反序列化
  16. public class IFProp
  17. {
  18. [PropertyOrder(11), Browsable(false), Category("1 标识"), DisplayName("1.1 标识"), Description("标识"), ReadOnly(true)]
  19. public long UniqueId { get; set; } = DateTime.Now.Ticks;
  20. [PropertyOrder(11), Browsable(true), Category("1 控制"), DisplayName("1.1 跳转步骤"), Description("跳转步骤 1-n")]
  21. public int GotoStepIndex { get; set; } = 1;
  22. [PropertyOrder(12), Browsable(true), Category("1 控制"), DisplayName("1.2 计数次数"), Description("达到计数次数后触发 1-n")]
  23. public int LimitNum { get; set; } = 1;
  24. [PropertyOrder(25), Browsable(true), Category("1 控制"), DisplayName("1.3 是否重置"), Description("达到计数要求触发后是否置0 (True-是;False-否)")]
  25. public bool Reset { get; set; }
  26. [PropertyOrder(27), Browsable(true), Category("1 控制"), DisplayName("1.4 禁用工序"), Description("禁用本工序(True-是;False-否)")]
  27. public bool Disable { get; set; }
  28. /// <summary>
  29. /// 序列化
  30. /// </summary>
  31. /// <param name="obj"></param>
  32. /// <returns></returns>
  33. public string serialize()
  34. {
  35. return JsonConvert.SerializeObject(this);
  36. }
  37. /// <summary>
  38. /// 反序列化
  39. /// </summary>
  40. /// <param name="json"></param>
  41. /// <returns></returns>
  42. public void deserialize(string json)
  43. {
  44. var o= JsonConvert.DeserializeObject<IFProp>(json);
  45. Type type = o.GetType();
  46. System.Reflection.PropertyInfo[] properties = type.GetProperties();
  47. foreach (System.Reflection.PropertyInfo property in properties)
  48. {
  49. string name = property.Name;
  50. if (!type.GetProperty(name).IsDefined(typeof(JsonIgnoreAttribute), true))
  51. {
  52. var value = property.GetValue(o);
  53. this.GetType().GetProperty(name).SetValue(this, value);
  54. }
  55. }
  56. }
  57. }
  58. }