I have an Person object that has attributes like string name
or int age
and Profession profession
. Profession has attributes like int id
and string description
.
Now what I want is to extract all the values into a string. The string should look like:
Name: Mr.X, Age: 24, Profession: {Id: 1, Description: IT Specialist}
But with my code I only get
Name: Mr.X, Age: 24, Profession: Models.Profession
My code is:
foreach (PropertyInfo pi in myObject.GetType().GetProperties())
{
values += pi.Name + ": " + pi.GetValue(myObject) + ", ";
}
What am I doing wrong? Please help.
Thanks in advance :)
Aucun commentaire:
Enregistrer un commentaire