public class A
{
public List<int> p1{get;set;}
public string p2{get;set;}
}
public class B
{
public List<A> p3{get;set;}
public string p4{get;set;}
}
怎么用propertyinfo.setvalue为B赋值?
{
public List<int> p1{get;set;}
public string p2{get;set;}
}
public class B
{
public List<A> p3{get;set;}
public string p4{get;set;}
}
怎么用propertyinfo.setvalue为B赋值?
解决方案
50
不能赋值B为A,他俩不是同类型的,你只能取出A中属性的值,然后将这个值赋给B中的属性
50
List<A> 要改为List<int>
A a = new A();
a.p1 = new List<int>();
a.p1.Add(9);
B b = new B();
b.p3 = new List<int>();
System.Reflection.PropertyInfo p = b.GetType().GetProperty("p3");
p.SetValue(b, a.p1, null);