版博士V2.0程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

70 regels
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.Device.Scanner;
  13. using static ProductionControl.UI.UIAxis;
  14. namespace ProductionControl.UI
  15. {
  16. //[TypeConverter(typeof(PropertySorter))] //此属性使类无法序列化和反序列化
  17. public class ScannerProp
  18. {
  19. public ScannerProp(ScannerType devType) {
  20. DeviceType=devType;
  21. }
  22. [PropertyOrder(1), Browsable(true), Category("设备"), DisplayName("设备类型"), Description("设备类型"), ReadOnly(true)]
  23. public ScannerType DeviceType { get;set; }
  24. [PropertyOrder(1), Browsable(true), Category("图像"), DisplayName("图像名称"), Description("图像名称"), ReadOnly(true), JsonIgnore]
  25. public string[] ImageList { get; set; }
  26. //
  27. [PropertyOrder(11), Browsable(true), Category("参数"), DisplayName("曝光"), Description("曝光")]
  28. public float ExposureTime { get; set; }
  29. [PropertyOrder(12), Browsable(true), Category("参数"), DisplayName("增益"), Description("增益")]
  30. public float Gain { get; set; }
  31. [PropertyOrder(13), Browsable(true), Category("参数"), DisplayName("帧率"), Description("帧率")]
  32. public float ResultingFrameRate { 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<ScannerProp>(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. }