.NET, C #, Reflection: lista pól pola, które samo w sobie ma pola
W .NET i C # załóżmyClassB
ma pole typuClassA
. Można łatwo użyć metodyGetFields
notowaćClassB
pola. Chcę jednakrównież wymienić pola tychClassB
pola, któresami mieć pola. Na przykład,ClassB
polex
ma polab
, s
, ii
. Chciałbym (programowo) wymienić te pola (jak sugerują moje komentarze w poniższym kodzie).
class ClassA
{
public byte b ;
public short s ;
public int i ;
}
class ClassB
{
public long l ;
public ClassA x ;
}
class MainClass
{
public static void Main ( )
{
ClassA myAObject = new ClassA () ;
ClassB myBObject = new ClassB () ;
// My goal is this:
// ***Using myBObject only***, print its fields, and the fields
// of those fields that, *themselves*, have fields.
// The output should look like this:
// Int64 l
// ClassA x
// Byte b
// Int16 s
// Int32 i
}
}