子属性能赋值,又怎么获取属性的子属性的值呢

解决方案 »

  1.   

    递归嘛,对属性返回的对象再调用反射:class A
    {
        public B b { get; set; }
    }
    class B
    {
        public string Name { get; set; }
    }foreach (var item in typeof(A).GetPropertites())
    {
        Console.WriteLine(item.PropertyType + " " + item.Name);
        foreach (var i2 in PropertyType.GetPropertites())
        {
            Console.WriteLine("\t" + i2.Name);
        }
    }
      

  2.   

    值一样啊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);
      

  3.   

    版主大哥,真的是属性名,试过了,我是想获取属性值
    我对Name赋值后
    然后这样写 i2.getvalue(item,null);  //这里会报错误,说对象和类型不匹配
    i2.getvalue(object obj,null) 这里的obj应该怎么写呢