Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using multiple values for one key in appSettings

I'm learning about how to use config files and I ran into some problems that I'm hoping someone here can give me some advice. It doesn't matter if my files are XML or not but the majority of examples I have read are using them and Im all for anything that makes my life easier.

the problem Im running into is that the appSettings file seems to be setup to only accept one value for one key and I would like to have something similar to:

<key="Machine List" value="Server105" />
<key="Machine List" value="Server230" />

Ive found a hack here but it was written over 6 years ago and I didn't know if there was a better way.

Again, it doesnt matter if this is XML, a flat file, etc.... Im just trying to learn how to use config files instead of hard coding values directly into the app.

Thanks for your help.

like image 515
Leroy Jenkins Avatar asked Nov 18 '10 13:11

Leroy Jenkins


2 Answers

if you really need to store multiple machines under the key, it would be more appropriate to do:

<key="Machine List" value="Server105,Server230" />

with the delimiter being a character of your choosing.

like image 104
Jeremy B. Avatar answered Sep 20 '22 00:09

Jeremy B.


An alternative to entry attributes would be to add child nodes to your setting node:

 <setting key="Machine List">
     <value>Server105</value>
     <value>Server230</value>
   </setting>

This way you don't need string manipulations to extract the different values.

like image 45
xtofl Avatar answered Sep 21 '22 00:09

xtofl