111,120
社区成员
发帖
与我相关
我的任务
分享
Rootobject config = new Rootobject();
PropertyInfo[] propertys = config.GetType().GetProperties();
foreach (var property in propertys)
{
if (property.PropertyType == typeof(string))
{
property.SetValue(config, "1111", null);
}
else if (property.PropertyType == typeof(Entry[]))
{
Entry[] entry = {
new Entry
{
A1 = "2222",
B1 = "2222"
},
new Entry
{
A1 = "3333",
B1 = "3333"
}
};
property.SetValue(config, entry, null);
}
}
我这样写的,能遍历,但是不能给数组赋值。还要怎么才能接着遍历类里的数组,然后赋值呢