has been studying the. Net Micro Framework font file (TINYFNT), because the Tinyfnt file header has a section of descriptive data, so want to define a structure, like VC directly read out from the file, so as to save the flow of parsing is very troublesome.
Did not think in the absence of direct instructions, presumably the designers think that the provision of streaming and serialization technology, all problems can be solved.
In the middle of the structure is a more complex things, there are many need to set the parameters, otherwise it is easy to make mistakes. Here is a description of the MSDN section that might help you understand the structure in the C # language.
You can customize how the structure is laid out in memory by using attributes. For example, you can use the StructLayout (layoutkind.explicit) and FieldOffset properties to create layouts that are called unions in C + +.
[System.Runtime.InteropServices.StructLayout(LayoutKind.Explicit)]
struct TestUnion
{
[System.Runtime.InteropServices.FieldOffset(0)]
public int i;
[System.Runtime.InteropServices.FieldOffset(0)]
public double d;
[System.Runtime.InteropServices.FieldOffset(0)]
public char c;
[System.Runtime.InteropServices.FieldOffset(0)]
public byte b;
}
In the previous code snippet, all the fields in TestUnion start from the same location in memory.
The following is another example of a field starting at another location that is explicitly set.
[System.Runtime.InteropServices.StructLayout(LayoutKind.Explicit)]
struct TestExplicit
{
[System.Runtime.InteropServices.FieldOffset(0)]
public long lg;
[System.Runtime.InteropServices.FieldOffset(0)]
public int i1;
[System.Runtime.InteropServices.FieldOffset(4)]
public int i2;
[System.Runtime.InteropServices.FieldOffset(8)]
public double d;
[System.Runtime.InteropServices.FieldOffset(12)]
public char c;
[System.Runtime.InteropServices.FieldOffset(14)]
public byte b;
}