How can I do deep reflection on an object. In other words, if a property of
an object is another object, I want to do reflection on that too and so on
until I arrive at value types (or string). Here is what I got so far, but I
don't know how to tell whether a property is an object or a value type. As
you can tell I am doing the entire thing via recursion.
private string GetObjectInfo(S ystem.Object o)
{
string s;
Type t = o.GetType();
PropertyInfo[] pis = t.GetProperties ();
s = "\n\n" + o.ToString();
for (int i=0; i<pis.Length; i++)
{
PropertyInfo pi = (PropertyInfo)p is.GetValue(i);
s += "\n\t" + pi.Name;
s += "=" + pi.GetValue(o, new object[]{});
//HOW DO I FIND OUT WHETHER THIS PROPERTY
//IS AN OBJECT?
if (pi.IsObject)
s += GetObjectInfo (pi)
}
return s;
}
Thanks.
--
Frank
an object is another object, I want to do reflection on that too and so on
until I arrive at value types (or string). Here is what I got so far, but I
don't know how to tell whether a property is an object or a value type. As
you can tell I am doing the entire thing via recursion.
private string GetObjectInfo(S ystem.Object o)
{
string s;
Type t = o.GetType();
PropertyInfo[] pis = t.GetProperties ();
s = "\n\n" + o.ToString();
for (int i=0; i<pis.Length; i++)
{
PropertyInfo pi = (PropertyInfo)p is.GetValue(i);
s += "\n\t" + pi.Name;
s += "=" + pi.GetValue(o, new object[]{});
//HOW DO I FIND OUT WHETHER THIS PROPERTY
//IS AN OBJECT?
if (pi.IsObject)
s += GetObjectInfo (pi)
}
return s;
}
Thanks.
--
Frank