版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 

63 строки
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 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 IFProp
  16. {
  17. [PropertyOrder(11), Browsable(false), Category("1 标识"), DisplayName("1.1 标识"), Description("标识"), ReadOnly(true)]
  18. public long UniqueId { get; set; } = DateTime.Now.Ticks;
  19. [PropertyOrder(11), Browsable(true), Category("1 控制"), DisplayName("1.1 跳转步骤"), Description("跳转步骤 1-n")]
  20. public int GotoStepIndex { get; set; } = 1;
  21. [PropertyOrder(12), Browsable(true), Category("1 控制"), DisplayName("1.2 计数次数"), Description("达到计数次数后触发 1-n")]
  22. public int LimitNum { get; set; } = 1;
  23. [PropertyOrder(25), Browsable(true), Category("1 控制"), DisplayName("1.3 是否重置"), Description("达到计数要求触发后是否置0 (True-是;False-否)")]
  24. public bool Reset { get; set; }
  25. [PropertyOrder(27), Browsable(true), Category("1 控制"), DisplayName("1.4 禁用工序"), Description("禁用本工序(True-是;False-否)")]
  26. public bool Disable { get; set; }
  27. /// <summary>
  28. /// 序列化
  29. /// </summary>
  30. /// <param name="obj"></param>
  31. /// <returns></returns>
  32. public string serialize()
  33. {
  34. return JsonConvert.SerializeObject(this);
  35. }
  36. /// <summary>
  37. /// 反序列化
  38. /// </summary>
  39. /// <param name="json"></param>
  40. /// <returns></returns>
  41. public void deserialize(string json)
  42. {
  43. var o= JsonConvert.DeserializeObject<IFProp>(json);
  44. Type type = o.GetType();
  45. System.Reflection.PropertyInfo[] properties = type.GetProperties();
  46. foreach (System.Reflection.PropertyInfo property in properties)
  47. {
  48. string name = property.Name;
  49. if (!type.GetProperty(name).IsDefined(typeof(JsonIgnoreAttribute), true))
  50. {
  51. var value = property.GetValue(o);
  52. this.GetType().GetProperty(name).SetValue(this, value);
  53. }
  54. }
  55. }
  56. }
  57. }