You cannot do that. There is no global switch. You have to set Pack
explicitly on every struct.
You can at least make you code more concise by adding a using
statement, and by writing StructLayout
rather than StructLayoutAttribute
:
using System.Runtime.InteropServices;
....
[StructLayout(LayoutKind.Sequential, Pack = 1)]