using System.Reflection; using System.Windows.Forms; using Uestc.Auto6.Dso.Core; using Uestc.Auto6.Dso.Core.Decode; using Uestc.Auto6.Dso.ComModel; using Uni_Trend.MSO7000X.Language; using Uni_Trend.MSO7000X.Common.Helper; using Uni_Trend.MSO7000X.UserControls; using System; using System.Linq; namespace Uestc.Auto6.Dso.Protocol.PCIe { public partial class PCIeSetControl : UserControl, IProtocolView { #region 属性定义 protected new Boolean DesignMode { get { Boolean rtnflag = false; #if DEBUG rtnflag = DesignTimeHelper.InDesignMode(this); #endif return rtnflag; } } public PCIeDecodePrsnt DestinDecodePrsnt { get => _DestinDecodePrsnt; set { if (_DestinDecodePrsnt != value) { _DestinDecodePrsnt = value; ///当有新的同步目标时,应先将目标中参数同步到本地属性中 if (_PCIeDecodePrsnt != null && value != null) { typeof(PCIeDecodePrsnt).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.CanWrite).ToList().ForEach(x => { x.SetValue(_PCIeDecodePrsnt, x.GetValue(value)); }); } } } } private PCIeDecodePrsnt _DestinDecodePrsnt; private PCIeDecodePrsnt _PCIeDecodePrsnt => Presenter as PCIeDecodePrsnt; public IProtocolPrsnt Presenter { get; set; } private FloatForm _FloatForm; #endregion 属性定义 public PCIeSetControl() { InitializeComponent(); } protected override void OnLoad(EventArgs e) { base.OnLoad(e); Init(); } private void Init() { GetDestinPrsnt(); } /// /// 获取需要同步的Prsnt /// 当时表示不需要与其他Prsnt进行同步 /// private void GetDestinPrsnt() { } /// /// 同步两个Prsnt /// /// 属性名称 private void DecodeSynchronization(String propertyName) { if (DestinDecodePrsnt == null) return; ///由于使用了进行判断具体同步的目标 ///因此参数不进行同步 if (propertyName == nameof(I2CDecodePrsnt.SDA)) return; if (String.IsNullOrEmpty(propertyName)) { typeof(I2CDecodePrsnt).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(x => x.CanWrite).ToList().ForEach(x => { x.SetValue(DestinDecodePrsnt, x.GetValue(_PCIeDecodePrsnt)); }); } else { PropertyInfo propertyInfo = typeof(PCIeDecodePrsnt).GetProperty(propertyName, BindingFlags.Public | BindingFlags.Instance | BindingFlags.NonPublic); if (propertyInfo != null) propertyInfo.SetValue(DestinDecodePrsnt, propertyInfo.GetValue(_PCIeDecodePrsnt)); } } public void UpdateView(String propertyName) { DecodeSynchronization(propertyName); if (String.IsNullOrEmpty(propertyName)) { UpdateView(); return; } } private void UpdateView() { this.GetType().GetMethods().Where(x => x.GetCustomAttribute() != null).ToList().ForEach(x => x?.Invoke(this, null)); this.Refresh(); } } }