Configuration sections

  • Thread starter Thread starter Marc Scheuner [MVP ADSI]
  • Start date Start date
M

Marc Scheuner [MVP ADSI]

Folks,

What's the big difference between the NameValueSectionHandler, and the
DictionarySectionHandler, when it comes to defining and handling my
own custom config sections? Is it really just the return type of the
values read from the .config file?

What are you using? What are the prons and cons for and against either
of the two options? Any preferences?

Thanks!
Marc

================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
 
To quote MSDN:

The following table shows the type of object the
ConfigurationSettings.GetConfig method returns for each configuration
section handler.

Configuration section handler Return type

DictionarySectionHandler Systems.Collections.IDictionary
NameValueSectionHandler
Systems.Collections.Specialized.NameValueCollection

It really seems that the return type is the only difference. Both use the
same XML structure (strangely enough, the MSDN example declares a dedicated
section group for the sample NameValueSectionHandler section. This might be
the second difference between the two).

I'd personally vote for NameValueSectionHandler since it returns a more
convenient NameValueCollection.
 
I'd personally vote for NameValueSectionHandler since it returns a more
convenient NameValueCollection.

Okay, thanks - one more thing. The docs say that the
NameValueCollection type returned is sorted

"NameValueCollection Class [C#]
Represents a sorted collection of associated String keys and String
values that can be accessed either with the key or with the index."

However, I seem to find this is not the case. Do you concur? Are the
collections you get returned from your XML app config files really
sorted??

Marc

================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
 
Marc,

I don't use them that heavily, actually, I haven't used config sections for
more than a year. So I can't probably say for sure.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://www.x-unity.net/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Marc Scheuner said:
I'd personally vote for NameValueSectionHandler since it returns a more
convenient NameValueCollection.

Okay, thanks - one more thing. The docs say that the
NameValueCollection type returned is sorted

"NameValueCollection Class [C#]
Represents a sorted collection of associated String keys and String
values that can be accessed either with the key or with the index."

However, I seem to find this is not the case. Do you concur? Are the
collections you get returned from your XML app config files really
sorted??

Marc

================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
 
Back
Top