I am communicating with a device with its provided dll drivers in C# using VS Express 2013. As a result I'm using some classes defined by the producer. I want to save/read some objects to a file but I cannot save them to a binary file directly because:
- These objects are not Serializable
- I cannot add Serializable to classes since they are provided with dll
An annoying solution is to save all information in the objects one by one, i.e. saving all integers, arrays, bools, etc.
using (Stream stream = File.Open(fileName, FileMode.OpenOrCreate))
{
var bF = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
bF.Serialize(stream, saveObj.measurementType);
bF.Serialize(stream, saveObj.Results);
bF.Serialize(stream, saveObj.TimeStamp);
bF.Serialize(stream, saveObj.TXPowerSet);
bF.Serialize(stream, saveObj.ValidCalFlags);
}
Is there a better solution so that I can save/read saveObj in a few steps?
It does not necessarily have to be a binary file.
Edit: Revised the question according to comments.