我正在使用Reflection来获取c#中所有类的字段,但现在我想在我的类中获取每个变量的GC生成。我怎么能这样做?
CSkyclass
{
float time = 0;
}
Sky = new CSkyclass();
void GetGeneration()
{
FieldInfo[] FieldArray = typeof(CSkyclass).GetFields(flags);
foreach(System.Reflection.FieldInfo Field in FieldArray)
{
string name = Field.Name; //"time"
int g = GC.GetGeneration(name); //should = GC.GetGeneration(Sky.time);
}
}
这甚至可能吗? 感谢
答案 0 :(得分:1)
您正在尝试生成字段的值:
GC.GetGeneration(field.GetValue(someInstance));