The classes store various program settings. I need to save these classes to files so that users can open and modify these files.

At first I used binary serialization. She has her flaw. For example, I saved a class in which there are 5 fields, then something changed in the program, and in this class there were 6 fields. As a result, deserialize the class from this file will not work.

Then I wrote my solution, which saved the classes in sqlite local db. It is convenient enough, but it also takes time to support the solution. And now, when faced with the need to upgrade one’s own solution, I thought that maybe it’s worth looking for something that is ready and more universal in order not to support its solution :)

So, we are looking for a ready-made solution that allows saving program classes to files. The main thing is that when the number of fields in a class changes, the file is deserialized, and it would be ideal if the missing fields are filled with default values.

  • one
    What about XML serialization? Specify the DefaultValue attribute. Do not forget to assign the same value in the constructor. - VladD

2 answers 2

Newton Json can not only work with json, but also with xml. It works very fast, and the documentation is good. I am sure that if you study this library, it will help you greatly not only in your current task. Good luck!

    In my opinion, application settings should be stored in app.config. You can create your section with all the necessary settings. Dig towards ConfigurationSection .

    Supports default values, collections, and many other goodies. Extend, eliminates the need to create additional files and comes out of the box. Example