それでは、コードから始めて、自分自身をよりよく説明できるようにしましょう。int フィールドを含む MyClass クラスがあり、Foo クラスにも MyClass がフィールドとして含まれています。リフレクションを使用して MyClass から int フィールドの値を取得したい。
public class Foo
{
public MyClass myClass;
}
public class MyClass
{
public int Integer = 1;
}
私が使うとき
Foo f = new Foo();
foreach(FieldInfo fi in f.GetType().GetFields())
{
//lets say now it enumerating myClass field
foreach(FieldInfo fi2 in fi.FieldType.GetFields())
{
return fi2.GetValue(f); //Here I need to use f.myClass, but I can't
//because it's generic method and I don't know what type I'm currently
//enumerating, so just typing f.myClass won't make it
}
}
問題は、f.myClass.Integer の値を取得する方法です。
前もって感謝します、
ポール