Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there any common way to save application settings in more advanced way, than plain .settings file?

Tags:

c#

wpf

There's a large WPF application with several modules, windows, self-written controls, etc. We need to persist state for some of elements of user interface. For example:

  • windows layout;
  • controls layout;
  • last accepted input;
  • various grids' state(columns' visibility, width, order)

.Settings file seems too plain for this because of no hierarchy in it. Why can't I just serialize some SettingsModel, containing everything I need and then restore it on application startup? The very important requirement for persistence mechanism is that it shoud be extensible: If I refactor settings structure, and will try to de-serialize the file created with some previous version of SettingsModel class, I will obviously fail.

So the quiestion is: are there any frameworks for persisting complex settings?

like image 278
Ilya Smagin Avatar asked Feb 02 '12 18:02

Ilya Smagin


People also ask

How can you save the desired properties of Windows Forms application?

A simple way is to use a configuration data object, save it as an XML file with the name of the application in the local Folder and on startup read it back.

Does app config get compiled?

Now you might be wondering what happens behind the scenes. Well, when you compile your application, the compiler actually copies the app. config file to the output folder, but gives it another name: When you start your application (ConsoleApp1.exe in our example), the matching config file will be loaded too.

How to access settings file c#?

Settings. settings is located in the My Project folder for Visual Basic projects and in the Properties folder for Visual C# projects. The Project Designer then searches for other settings files in the project's root folder. Therefore, you should put your custom settings file there.

Why use app config c#?

App. Config is an XML file that is used as a configuration file for your application. In other words, you store inside it any setting that you may want to change without having to change code (and recompiling). It is often used to store connection strings.


2 Answers

As Rachel suggested, you could use XML serialization, i for one always use that for settings, it has some tolerance for changes but i do not know if it would fit all your needs.

like image 59
H.B. Avatar answered Sep 19 '22 19:09

H.B.


The .Settings file supports changing the structure over time. You don't even need to use the Settings.cs file you can make your own settings providers and have them populate from the config file, each with their own customized Upgrade method to handle changes in the structure.

like image 41
Scott Chamberlain Avatar answered Sep 18 '22 19:09

Scott Chamberlain