You can only do that if you type has a fixed layout and has no managed members. Structs are fixed by default. Classes can attributed to have a fixed layout.
(I am not showing how, as you really do not need it. It is only important when doing interop.)