如何获取类的所有属性的列表?
public class ReqPerson
{
public String Name { get; set; }
public String Age { get; set; }
public List<Detail> Details { get; set; }
}
public class Detail
{
public String Job { get; set; }
public String City { get; set; }
}
这是我的代码,结果仅获得属性类ReqPerson,而不是类Detail。
private static PropertyInfo[] GetProperties(object obj)
{
return obj.GetType().GetProperties();
}
ReqPerson req = new ReqPerson();
// Get property array
var properties = GetProperties(req);
foreach (var p in properties)
{
string name = p.Name;
var value = p.Getvalue(Inq.ReqInquiry(req,null);
Response.Write(name);
Response.Write("</br>");
}
有人可以改善我的代码吗?