Question

I have this list say product Type:

Type1
Type2 
Type3

and so on Now this list will keep increasing time to time and will be set via appsettings.

Now the key will not be really like Type1 orType2 these will be different. Like say

<add key="FoodItems" value="something"/>
<add key="Cosmetics" value="xyz"/>

so on.. So when I write the code i need to get the key and value from app config, I know how to get all keys but I want to put these under certain category so that I don't have to Parse the whole config file I will parse just this section and get all the types under it.

something like

<ItemList>
 <add key="FoodItems" value="something"/>
    <add key="Cosmetics" value="xyz"/>
</ItemList>

Is it possible to do something like that in appsettings? Or some other way but yes in appconfig specifically.

Was it helpful?

Solution

What you want is your own custom Configuration Section. Here is a solid guide I've used before.

When using your own configuration section, you don't have to use a Dictionary type like appSettings does - you can define multiple properties, which sounds like what you are looking for.

An alternative is using sectiongroup element as indicated here.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top