I'm trying to create a section in web config where I can have a list of names.
So to do that I have done the following:
public class MyCustomSection : ConfigurationSection
{
public string Name
{
get
{
return (string) this["name"];
}
set
{
this["name"] = value;
}
}
}
In the web.config I have added the following:
<configSections>
<sectionGroup name="myCustomSectionGroup">
<section name="myCustomSection" type="MySite.MyCustomSection"/>
</sectionGroup>
</configSections>
<myCustomSectionGroup>
<myCustomSection name="MyFirstName"></myCustomSection>
<myCustomSection name="MySecondName"></myCustomSection>
</myCustomSectionGroup>
According to the MS guide, this is how its done: https://msdn.microsoft.com/en-us/library/2tw134k3.aspx
The next part I need to do is grab (in a IEnumerable format, list, array, anything really) myCustomSection. I need to know all the entries. However, I can't seem to find how that is done anywhere. Looking at the ConfigurationManager.GetSection
, it returns an Object, not a list or ConfigurationSectionGroup
or ConfigurationSection
.
How do I grab the values from my custom section and loop over them, lets say just output them in console, their names.