反射

Type type = typeof(对象); //获取类型
var userActivityModel = (对象)Activator.CreateInstance(type); //创建对象
foreach (var item in model.ChildControl)
{
int index = 0;
foreach (var Prop in type.GetProperties())
{
if (index == 1)
{
break;
}
if (Prop.Name == item.fileName)
{
Prop.SetValue(userActivityModel, item.content);//设置值
index = 1;
break;
}
}
}

posted @ 2023-06-12 17:17  煜灵  阅读(30)  评论(0)    收藏  举报