版博士V2.0程序
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 

66 rindas
2.1 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.UIAxis;
  13. namespace ProductionControl.UI
  14. {
  15. //[TypeConverter(typeof(PropertySorter))] //此属性使类无法序列化和反序列化
  16. public class LightProp
  17. {
  18. public LightProp(int portNum) {
  19. PortNum = portNum;
  20. }
  21. [PropertyOrder(1), Browsable(true), Category("设备"), DisplayName("端口号"), Description("端口号"), ReadOnly(true), JsonIgnore]
  22. public int PortNum { get;private set; }
  23. //
  24. [PropertyOrder(11), Browsable(true), Category("通道"), DisplayName("通道号"), Description("通道号")]
  25. public int ChannelIndex { get; set; } = 1;
  26. [PropertyOrder(12), Browsable(true), Category("数据"), DisplayName("亮度"), Description("亮度")]
  27. public int DigitalValue { 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<LightProp>(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. }