This will give you the byte[] you want. It is worth noting here that I did not use a serializer, because you need a very crude string, and there are no serializers (that I know) that can serialize it the same way you want OOB. However, such a simple serialization makes sense.
var bytes = Encoding.UTF8.GetBytes(string.Format("commandID={0};MsgData={1}", o.commandID, o.MsgData));
Finally, if you have more properties unknown to me, you can use reflection.
source share