I'm trying to convert an object with only int fields (ushort, ulong, uint, int, etc.) into a byte array containing each int as a byte in the order that it appears in the object. For example, if I have an object of the form
obj = {subobj: {uint firstProp: 500, ushort secondProp: 12}, byte lastProp: 5}
then I expect the byte array to be
{0, 0, 1, 244, 0, 12, 5}
I tried to create this byte array by using Serialization (as described in this answer), but I'm noticing there's a bunch of stuff before and after each byte. Based on this website, I believe this represents the database and the file, which I don't want.
I know that in C++ I can use reinterpret_cast<uint8_t*>(obj)
to get the desired result. Is there an equivalent way to do this in C#?