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.Util { public class ControlsImprot { /// /// 控件导入 /// /// 控件类型 /// 控件实体类 /// 前端控件集合 public static void ControlImport(object obj, List McControls) where T : class { PropertyInfo[] sourcePropertyInfoList = obj.GetType().GetProperties(); foreach (PropertyInfo sourceProperty in sourcePropertyInfoList) { string name = sourceProperty.Name; var pro = McControls.FirstOrDefault(x => x.Name == name) as T; sourceProperty.SetValue(obj, pro); } } } }