is it possible to have app.config file like this :
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="someKey" value="valueHere"/>
<add key="anotherKey" value="valueHere"/>
<add key="listOfValues">
<value1/>
...
<valueN/>
</add>
</appSettings>
</configuration>
I mean, I want to have a key in config file that returns a list of values.How to do it? Think it's pretty easy, but I just can't find any examples
UPD : maybe I should put multiple values separated by semicolon and then just split them?.. But I think it is not very good idea...
Now you can use ConfigurationSettings.AppSettings [key] as always, as well as ConfigurationSettings.AppSettings.GetValues (key), which returns a string [] with all the values for that key. You'll find an example in the demo project that uses both.
When you create a (non-web) .NET Framework application in Visual Studio, an app.config file is added to your project. When you create a class library or a .NET Core project, such a file is not included, although it can be done afterward. In a web project (i.e. ASP.NET) you will use a similar file, the web.config.
Using a de-compiler (like the great Lutz Roeder's Reflector ), we'll find the line that adds new values to the collection from the config files looks like this: As you may know, the first form replaces the value if the key already exists in the collection.
Since ConfigurationSettings.AppSettings, the easiest standard to read app settings uses this handler in a very particular way, developers usually have to create a custom section and read values using ConfigurationSettings.GetConfig and lots of casts. We'll hack AppSettings to make our life easier, and learn some interesting things.
I don't think the standard key/value pair config settings can do it, but with a little more coding you can have all the configuration XML goodness you want with a custom config section.
Don't know if what you're asking is possible. But what I do is I concatenate values using a separator like ";" for instance.
So you have something like:
<add key="runningDays" value="Mon;Tue;Wed;Thu;Fri"/>
Then I split the value string from config using the separator to get the list of possible values for the given key.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With