This is what I\'ve come up with so far, but it doesn\'t seem very optimal, any ideas on better approaches?
public void ToBytes(object[] data, byte[] buffer)
Probably, you should consider using BinaryFormatter
instead:
var formatter = new BinaryFormatter();
var stream = new MemoryStream();
formatter.Serialize(stream, obj);
byte[] result = stream.ToArray();
Beside that, there are some pretty good serialization frameworks like Google Protocol Buffers if you want to avoid reinventing the wheel.