0

Currently in the app.config of a program I have a Object Group where I define Each Object as a section in the group. However the names of each Section in the group could change, so I can't address each Section by a name when I read in there values. Is there a way to read in all the sections of a group without knowing the names of the section in the group?

Currently I have solved this problem by also having another section with a comma separated list of all the object names in the object section. However I would rather not have to define all the objects like this.

Thank you

Lightning77
  • 313
  • 5
  • 14
  • 1
    Is the app.config the best place to do this? This sounds like a separate XML file might be the better choice. – Doug Dawson Mar 07 '16 at 18:50
  • Possible duplicate of [How to get all sections by name in the sectionGroup applicationSettings in .Net 2.0](http://stackoverflow.com/questions/14963870/how-to-get-all-sections-by-name-in-the-sectiongroup-applicationsettings-in-net) – Matias Cicero Mar 07 '16 at 18:51
  • app.config should really contain static data that is not changed programmatically at run time. You should look at using a file (maybe xml or json) or a Settings class (you can add it to the project in VS and configure it in a designer). – Igor Mar 07 '16 at 18:54

1 Answers1

0

I think one solution is to read app.config file using a custom reader like the one here.

However, I recommend to use app.config to store a minimum, rarely changed information. A database is a very good option to store various data. It allows to easily change the data, to have a GUI, if the information must be changed by a non administrator etc.

Community
  • 1
  • 1
Alexei - check Codidact
  • 22,016
  • 16
  • 145
  • 164