How do I get a list of all the properties of a class?
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; }
}
This is my code, and the result only get properties class ReqPerson, not for class 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>");
}
Anybody can improve my code?