I have to iterate through all members of a class and display them in a Tree. The Tree-Handling can be ignored for now, at this point I'd be satisfied with just getting all class members in a simple list.
All the examples I could find (for instance Recursively Get Properties & Child Properties Of A Class) only return the first two members of the following class cTest:
public class cTest
{
public String str1;
public int intwert1;
public cParent Parent = new cParent();
}
public class cParent
{
public String parentStr1;
}
The field public cParent Parent is not found and not processed recursively. I could already tell that for the following code:
Type t = typeof(cTest);
PropertyInfo[] propertyInfos;
MemberInfo[] propertyMembers;
propertyInfos = t.GetProperties();
propertyMembers = t.GetMembers();
...propertyInfos does not contain public cParent Parent, but propertyMembers does contain public cParent Parent!
edit
thx, but still stuck. The following code gives the same informations for all class members
foreach (FieldInfo p in t.GetFields())
{
Console.WriteLine("-");
Console.WriteLine(p.GetType().ToString());
Console.WriteLine(p.Name.ToString());
Console.WriteLine(p.MemberType.GetType().ToString());
Console.WriteLine(p.MemberType.GetTypeCode().ToString());
Console.WriteLine(p.MemberType.ToString());
}
output: ^
System.Reflection.RtFieldInfo
str1
System.Reflection.MemberTypes
Int32
Field
-
System.Reflection.RtFieldInfo
int1
System.Reflection.MemberTypes
Int32
Field
-
System.Reflection.RtFieldInfo
Parent
System.Reflection.MemberTypes
Int32
Field