日期:2014-05-17  浏览次数:20829 次

如何用反射获取属性的子属性的值
子属性能赋值,又怎么获取属性的子属性的值呢

------解决方案--------------------
值一样啊

class A
 {
     public B b { get; set; }
 }
 class B
 {
     public string Name { get; set; }
 }

A a = new A();
a.b = new B() { Name = "123" };

objb = a.GetType().GetProperty("b").GetValue(a, null);
string s = (string)a.GetType().GetProperty("b").PropertyType.GetProperty("Name").GetValue(objb, null);