Supposing I have the following classes;
public class Foo
{
public string Reference { get; set; }
public CompanyModel Company { get; set; }
public CallDataModel CallData { get; set; }
}
public class CompanyModel
{
public string Name { get; set; }
}
public class CallDataModel
{
public IEnumerable<CallModel> Item { get; set; }
}
public class CallModel
{
public string Name { get; set; }
public int Value { get; set; }
}
Using reflection please can someone help me iterate through all properties including the IEnumerable collection.
I would like to be able to map out each propery name and corresponding value within a recursive method.
For example;
public void GetPropertiesRescursively<T>(this T model)
{
foreach (PropertyInfo prop in model.GetType().GetProperties())
{
// Do something
}
}
Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire