现在又俩个实体:public class User{ public string Id { get; set; }public string Email { get; set; }public University University { get; set; }}public class University{public string Id { get; set; }public stUring Name{ get; set; }}程序入口public void Main(){ User u=new User(); //赋值 string str= Serialize(u);}public string Serialize( object o){ //在这里这样获取University的Name属性值。} 当然以上并不符合实际开发环境。只是想知道递归反射取值。大侠们帮忙一下????
1 回答
蓝山帝景
TA贡献1843条经验 获得超7个赞
Type type = o.GetType();
PorpertyInfo pUniversity = type.GetProperty("University");
Type tUniversity = pUniversity.ReturnType;
PropertyInfo pName = tUniversity.GetProperty("Name");
string name = pName.GetValue(pUniversity.GetValue(o, null), null);
return name;
- 1 回答
- 0 关注
- 693 浏览
添加回答
举报
0/150
提交
取消