My application is a small C# database, and I'm using BinaryWriter
to save the database to a file which is working fine with the basic types such as bool, uint32 etc.
Although I've got a variable that is of type Object
(allowing the user to store any data type), however as my application doesn't (nor needs to) know the real type of this variable, I'm unsure how to write it using BinaryWriter
.
Is there a way I could perhaps grab the memory of the variable and save that? Would that be reliable?
Edit:
The answer provided by ba_friend has two functions for de/serialising an Object to a byte array, which can be written along with its length using a BinaryWriter.