Click here to Skip to main content
15,913,486 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello!

There are some things that really grinds my gears right now.
I read lot about custom configuration sections and aplication settings, but I can NOT find one good article/explanation how to create nested settings using Settings.settings.
If you add Settings.settings file to your "Properties", it will be available in code if you access it like this:
Properties.Settings.Default.SomeExampleString;


If I add second file, named Settings2.settings, it can be accessed like this:
Properties.Settings1.Default.SomeNextExampleString;


But how to make it to look like:
Properties.Settings.Default.FirstString;
Properties.Settings.Advanced.SecondString;
Properties.Settings.Basic.ThirdString;


Or it is even possible, when Settings.Designer.cs file is autogenerated?
I would like to use Settings.settings because of it's implemented save and reset methods.
Any ideas?
Posted

1 solution

In my personal opinion, application setting is somewhat morally obsolete. Instead, I use much more powerful and easy-to-use weapon: Data Contract: http://msdn.microsoft.com/en-us/library/ms733127.aspx[^].

It allows to store any object graph in stream and restore it back. The approach is absolutely non-intrusive: you don't modify data types, don't follow any rules (no access modifiers, implementing any interfaces, nothing), just add some attributes to types and members to became part of contract. Isn't it the best mechanism for any kinds of settings?

And, to put the file in write place, please see:
http://msdn.microsoft.com/en-us/library/system.environment.getfolderpath.aspx[^],
http://msdn.microsoft.com/en-us/library/system.environment.specialfolder.aspx[^].

This way, you can use either application data per user account, or the one for "all users", or anything like that.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900