using Mesnac.Action.ChemicalWeighing.AutoControl.Entity; using Mesnac.Controls.Base; using Mesnac.Controls.ChemicalWeighing; using Mesnac.Controls.Default; using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace Mesnac.Action.ChemicalWeighing.AutoControl { public class ControlsHelper { /// /// 控件导入 /// public static void ControlImport(MCTextBoxEntity textE, ButtonEntity buttonE, MCComboBoxEntity comboE, MCLabelEntity labelE, MCRadioButtonEntity radioE, List McControls) { FillBase(textE, McControls); FillBase(buttonE, McControls); FillBase(comboE, McControls); FillBase(labelE, McControls); FillBase(radioE, McControls); } private static void FillBase(object E, List McControls) where T : class { PropertyInfo[] sourcePropertyInfoList = E.GetType().GetProperties(); foreach (PropertyInfo sourceProperty in sourcePropertyInfoList) { string name = sourceProperty.Name; var pro = McControls.FirstOrDefault(x => x.Name == name) as T; sourceProperty.SetValue(E, pro); } } } }