我有一个固定大小的结构,我试图编组。此结构包含当前版本的结构的许多有用字段以及末尾未使用空间的指定数量,这些空间留作未来修改使用。
我应该如何设计这个结构,以便在修改结构时保留空间的大小会自动更新?
而下面将解决我的问题
'Variable size structure
<StructLayout(LayoutKind.Sequential, Pack:=1)>
Structure UsefulData
Dim foo As SByte
Dim bar As Integer
Dim foobar As Short
End Structure
Const MAX_SIZE As Integer = 20
'Fixed size structure
<StructLayout(LayoutKind.Sequential, Pack:=1, Size:=MAX_SIZE>
Structure Data
Dim current As UsefulData
<MarshalAs(UnmanagedType.ByValArray, SizeConst:=MAX_SIZE-System.Runtime.InteropServices.Marshal.SizeOf(GetType(UsefulData)))>
Dim reserved As SByte()
End Structure
但不编译为System.Runtime.InteropServices.Marshal.SizeOf(GetType(UsefulData))
不是一个常量表达式。有任何想法吗?