How to save C # application state to be able to download later

I have a program in which the user adds several objects to the scene. All of these objects are represented as classes. Now I want the user to be able to save the script, so it can be downloaded again.

Is there some kind of genereic save method that I can use, or do I need to write my own, which saves the values ​​of all properties, etc., and then creates new objects and inserts the saved values ​​into them when the user reloads the script.

/ P

Edit: Thanks for the quick answers guys. I am actually storing the default values ​​for objects in the SQL compact 3.5 database right now. Therefore, if someone knows how to serialize SQL, this will be great information.

Edit 2: Thanks again! I am going to serialize in xml and then store it as a string in an SQL database.

+3
source share
5 answers

Assuming your objects have all the values ​​available as public, you can use the XMLSerializer to convert the object to an XML string, and then use the XMLDeserializer to recreate the object.

There is an extension method for here .

If you have private variables, you can still write your own serialize / deserialize methods.

Edit in response to the original editing of the question:

. ORM (Object Relational Mapper) .

+5

. , , .

, , Xml Binary . System.Runtime.Serialization. Xml Binary , .

xml , 1.0. 1.0, 1.1. , 1.0 → 1.1. , ( ), xml , Product1/Product1.1/etc, , .

, , , , . SqlLite 1 , - , .

+2

.NET Serialization, . .

+1

db4o, .

+1

.NET - , , . , . / , , , , , . SerializationExceptions .

I think that you will also have this problem with the database, except that I assume that it will be processed by any method that you use to transfer existing databases to the latest version (for example, adding a new column to a table or attribute RDBMS ODBMS).

0
source

All Articles