This is the extract from my app.config file:
<configSections>
<section name="1"
type="System.Configuration.DictionarySectionHandle r" />
<section name="2"
type="System.Configuration.DictionarySectionHandle r" />
<section name="3"
type="System.Configuration.DictionarySectionHandle r" />
</configSections>
<1>
<add key="DayOrMonth" value="M" />
<add key="NoOfDaysOrMonths" value="3" />
</1>
<2>
<add key="DayOrMonth" value="M" />
<add key="NoOfDaysOrMonths" value="2" />
</2>
<3>
<add key="DayOrMonth" value="D" />
<add key="NoOfDaysOrMonths" value="14" />
</3>
GetSectionSettings() code that I posted DOES WORK for me. I simply perform
this call:
GetSectionSettings("1");
GetSectionSettings("2");
GetSectionSettings("3");
and the method gets values for each element in each section (M and 3 for
section "1", M and 2 for section "2", D and 14 for section "3") and does some
processing based on those values.
I don't want to hard-code "1", "2", "3" when I call GetSectionSettings
because there could be 50 sections, not just 3, and I don't need my program
to know what the names of those sections are, I want the program to figure
that out by looping through <configSectionselements. It shouldn't be even
necessary for me to post GetSectionSettings() code because it's got NOTHING
to do with how I would loop through <configSectionselements.
"Peter Duniho" wrote:
On Wed, 08 Oct 2008 12:12:19 -0700, Eve <Ev*@discussions.microsoft.com>
wrote:
Again, this is my code for GetSectionSettings method that accepts a
section
name as a parameter and retrieves the section's settings:
public void GetSectionSettings(string sectionName)
{
IDictionary configTable = (IDictionary)ConfigurationManager.GetSection
(sectionName);
string dayOrMonth = configTable["DayOrMonth"].ToString();
...
}
I don't see any way for that method to work generally. It can only work
for sections that implement the IDictionary interface, and you haven't
explained why the containing section does, never mind what type is
returned by that section.
I DON'T have any code that loops through <sectionelements within
<configSectionsbecause I HAVE NO CLUE HOW TO DO IT - that's why I
posted my
question on this forum.
I'm not asking for the code that you can't write. But you haven't even
posted a concise-but-complete code sample of what _does_ work.
Please see http://www.yoda.arachsys.com/csharp/complete.html and
http://www.yoda.arachsys.com/csharp/incomplete.html