This is the extract from my app.config file:
<configSections >
<section name="1"
type="System.Co nfiguration.Dic tionarySectionH andler" />
<section name="2"
type="System.Co nfiguration.Dic tionarySectionH andler" />
<section name="3"
type="System.Co nfiguration.Dic tionarySectionH andler" />
</configSections>
<1>
<add key="DayOrMonth " value="M" />
<add key="NoOfDaysOr Months" value="3" />
</1>
<2>
<add key="DayOrMonth " value="M" />
<add key="NoOfDaysOr Months" value="2" />
</2>
<3>
<add key="DayOrMonth " value="D" />
<add key="NoOfDaysOr Months" value="14" />
</3>
GetSectionSetti ngs() code that I posted DOES WORK for me. I simply perform
this call:
GetSectionSetti ngs("1");
GetSectionSetti ngs("2");
GetSectionSetti ngs("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 GetSectionSetti ngs
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 <configSections elements. It shouldn't be even
necessary for me to post GetSectionSetti ngs() code because it's got NOTHING
to do with how I would loop through <configSections elements.
"Peter Duniho" wrote:
On Wed, 08 Oct 2008 12:12:19 -0700, Eve <Ev*@discussion s.microsoft.com >
wrote:
Again, this is my code for GetSectionSetti ngs method that accepts a
section
name as a parameter and retrieves the section's settings:
public void GetSectionSetti ngs(string sectionName)
{
IDictionary configTable = (IDictionary)Co nfigurationMana ger.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 <sectionelement s within
<configSections because 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