I'm trying to get the field types of an unsafe struct using some fixed fields. The fixed fields FieldType do not return the actual type.
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public unsafe struct MyStruct
{
public UInt32 Field1;
public fixed sbyte Field2[10];
public UInt64 Field3;
}
void Test()
{
var theStruct = new MyStruct();
string output = "";
foreach (FieldInfo fi in theStruct.GetType().GetFields(BindingFlags.Public | BindingFlags.Instance))
{
output += fi.Name + ": " + fi.FieldType.ToString() + "\r\n";
}
}
Output:
Field1: System.UInt32
Field2: TestProjectNS.MyStruct+<Field2>e__FixedBuffer0
Field3: System.UInt64
I'm looking for Field2
to tell me it's sbyte
instead of TestProjectNS.MyStruct+<Field2>e__FixedBuffer0