反射常用在获取一个类的字段,方法,属性 等
//这里需要用到反射,去获取类的属性
Type typeModule = typeof(UserAttachModule);
PropertyInfo[] properties = typeModule.GetProperties(); //获取到类的属性
foreach (PropertyInfo property in properties)
{
if ("m" + TempName == property.Name)
{
//获取到类的对象的属性值
object result = ContainProperty(_viewModel, property.Name);
if (result is bool)
{
//给对象的属性值赋值,这里是CheckBox
_viewModel.GetType().GetProperty(property.Name).SetValue(_viewModel, true);
}
}
}
UserAttachModule 类名
_viewModel UserAttachModule 的对象