版博士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.

преди 2 години
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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.UIAxisDev;
  13. namespace ProductionControl.UI
  14. {
  15. //[TypeConverter(typeof(PropertySorter))] //此属性使类无法序列化和反序列化
  16. public class ForProp
  17. {
  18. [PropertyOrder(11), Browsable(false), Category("1 标识"), DisplayName("1.1 标识"), Description("标识"), ReadOnly(true)]
  19. public long UniqueId { get; set; } = DateTime.Now.Ticks;
  20. [PropertyOrder(11), Browsable(true), Category("1 控制"), DisplayName("1.1 跳转步骤"), Description("跳转步骤 1-n")]
  21. public int GotoStepIndex { get; set; } = 1;
  22. [PropertyOrder(12), Browsable(true), Category("1 控制"), DisplayName("1.2 循环次数"), Description("循环次数 1-n")]
  23. public int LimitNum { get; set; } = 1;
  24. [PropertyOrder(25), Browsable(true), Category("1 控制"), DisplayName("1.3 是否重置"), Description("达到循环次数后是否置0 (True-是;False-否)")]
  25. public bool Reset { get; set; }
  26. [PropertyOrder(27), Browsable(true), Category("1 控制"), DisplayName("1.4 禁用工序"), Description("禁用本工序(True-是;False-否)")]
  27. public bool Disable { 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<ForProp>(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. }