版博士V2.0程序
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 
 
 

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