You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
999 B
C#
32 lines
999 B
C#
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
|
|
{
|
|
/// <summary>
|
|
/// 控件导入
|
|
/// </summary>
|
|
/// <typeparam name="T">控件类型</typeparam>
|
|
/// <param name="obj">控件实体类</param>
|
|
/// <param name="McControls">前端控件集合</param>
|
|
public static void ControlImport<T>(object obj, List<Control> 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);
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|