In .NET & C#, suppose ClassB
has a field that is of type ClassA
.
One can easily use method GetFields
to list ClassB
\'
You need to write a recursive method that takes an object, loops through its fields (obj.GetType().GetFields()
), and prints the value of a field of primitive type, and calls itself for a class (other than String
).
You'll need a parameter for the indent size for use with recursion.
EDIT: You'll also need some mechanism to prevent a stack overflow for cyclic object graphs. I recommend placing a limit on the indent parameter.