我正在尝试显示结构的内容,如此
private void GetEntityInfo(FieldInfo fieldInfo, Entity entity)
{
if (fieldInfo.FieldType.IsNested)
{
// THIS PART IS WRONG!
//foreach (var field in fieldInfo.GetType().GetFields())
//{
// GetEntityInfo(field, entity);
//}
}
else
{
var info = new EntityInfo
{
Index = (int) Marshal.OffsetOf(typeof(Entity), fieldInfo.Name),
Name = fieldInfo.Name,
Value = fieldInfo.GetValue(entity).ToString()
};
EntityInfoList.Add(info);
}
}
struct里面有嵌套的结构。我如何获取嵌套结构的字段?如果它没有嵌套,则值按预期出现。像。的东西。
struct Entity
{
int c;
Something something;
int d;
int e;
}
struct Something
{
int a;
int b;
}