.NET & C#에서는 ClassB
의 필드가 ClassA
인 것으로 가정합니다. 님의 필드를 목록으로 만들려면 GetFields
메서드를 쉽게 사용할 수 있습니다. 그러나 도의 필드는 ClassB
필드에 표시되며 필드에는 필드가 있습니다. 예를 들어, ClassB
의 필드 x
은 b
, s
및 i
필드를 포함합니다. 해당 필드를 (프로그래밍 방식으로) 나열하고 싶습니다 (아래 코드에서 내 의견에 의해 제안 된 것처럼)..NET, C#, Reflection : 필드 자체의 필드 필드를 나열하십시오.
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
}
}
일부 불쾌한 LINQ 후보입니까? :) – xyz