.NET & C#では、ClassB
にフィールドがClassA
であるとします。 方法GetFields
を簡単に使用してClassB
のフィールドを一覧表示できます。 しかし、私はにものフィールドをリストしています。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