I’m using a BinaryFormatter to serialize my object. I have various object types in their relevant lists. Is there a ‘best’ way to serialize all the objects into one file, but be able to separate them on deserialization? At the moment, I’m deserializing the whole file and checking a specific field in each object to see what list I should re-add them to after deserialization. For example all my Ford cars have the ‘FORD’ field, Toyota have ‘TOYOTA’ etc.. Upon deserialization, I ‘foreach’ through the objects, check their ‘company’ field and then assign them to a List<Company>.
I’m not sure if this is the most efficient way of doing things. Any suggestions?
Thanks for the help
This one’s easy … instead of serializing each individual item. Just make a “parent” class which simply has a property for each item type. And then you can serialize that one object. When you deserialize it on the other end it will already be full sorted out for you.