Как мне получить список всех свойств класса?
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>");
}
Кто-нибудь может улучшить мой код?