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

71 行
2.6 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 AssistClient.UI.PropExtend;
  12. using static AssistClient.UI.UIAxisDev;
  13. namespace AssistClient.UI
  14. {
  15. //[TypeConverter(typeof(PropertySorter))] //此属性使类无法序列化和反序列化
  16. public class LightDevProp
  17. {
  18. public LightDevProp(int portNum) {
  19. PortNum = portNum;
  20. }
  21. [PropertyOrder(1), Browsable(true), Category("1 设备"), DisplayName("端口号"), Description("端口号"), ReadOnly(true), JsonIgnore]
  22. public int PortNum { get;private set; }
  23. //
  24. [PropertyOrder(11), Browsable(true), Category("2 通道"), DisplayName("通道号"), Description("通道号")]
  25. public int ChannelIndex { get; set; } = 1;
  26. [PropertyOrder(12), Browsable(true), Category("3 数据"), DisplayName("亮度"), Description("亮度")]
  27. public int DigitalValue { get; set; }
  28. [PropertyOrder(25), Browsable(true), Category("4 控制"), DisplayName("4.1 运行前Sleep(ms)"), Description("休息时间")]
  29. public uint SleepPre { get; set; }
  30. [PropertyOrder(26), Browsable(true), Category("4 控制"), DisplayName("4.2 运行后Sleep(ms)"), Description("休息时间")]
  31. public uint SleepLater { get; set; }
  32. [PropertyOrder(27), Browsable(true), Category("4 控制"), DisplayName("4.4 禁用工序"), Description("禁用本工序")]
  33. public bool Disable { get; set; }
  34. /// <summary>
  35. /// 序列化
  36. /// </summary>
  37. /// <param name="obj"></param>
  38. /// <returns></returns>
  39. public string serialize()
  40. {
  41. return JsonConvert.SerializeObject(this);
  42. }
  43. /// <summary>
  44. /// 反序列化
  45. /// </summary>
  46. /// <param name="json"></param>
  47. /// <returns></returns>
  48. public void deserialize(string json)
  49. {
  50. var o= JsonConvert.DeserializeObject<LightDevProp>(json);
  51. Type type = o.GetType();
  52. System.Reflection.PropertyInfo[] properties = type.GetProperties();
  53. foreach (System.Reflection.PropertyInfo property in properties)
  54. {
  55. string name = property.Name;
  56. if (!type.GetProperty(name).IsDefined(typeof(JsonIgnoreAttribute), true))
  57. {
  58. var value = property.GetValue(o);
  59. this.GetType().GetProperty(name).SetValue(this, value);
  60. }
  61. }
  62. }
  63. }
  64. }