I have a program in which the user adds multiple objects to a scene. These objects are all represented as a classes. Now I want the user to be able to save the scenario, so it can be loaded again.
Is there some genereic save method I can use, or do I have to write my own that saves the values of all properties and such and then create new objects and insert the saved values into them when the user loads the scenario again.
/P
Edit: Thanks for the quick replys guys. I’m actually storing default values for the objects in a SQL compact 3.5 database right now. So if anyone knows how to serialize to SQL, that would be great info.
Edit 2: Thanks again! I’m going to serialize to xml, then store it as a string to the SQL database.
Assuming your objects have all values available as public properties, you can use an XMLSerializer to convert the object to an XML string, then use a XMLDeserializer to re-create the object.
There is an extension method to accomplish this here.
If you have private variables, you can still write your own custom serialize/deserialize methods.
Edit in response to original question edit:
You can use any of these serialization techniques to store the string into a database. Another option would be to use an ORM (Object Relational Mapper) to bridge the gap between your objects and the databases.