Implicit ConfigurationElementCollection sections

316 views Asked by At

The System.Configuration connection string configuration classes define:

ConnectionStringsSection : ConfigurationSection

ConnectionStringSettingsCollection : ConfigurationElementCollection

ConnectionStringSettings : ConfigurationElement

But the section in the config file looks like:

 <connectionStrings>
    <add name="Foo" connectionString="Whatever" />
 </connectionStrings>

so it appears that the ConnectionStringSettingsCollection is implicit.

I would like to have this same behaviour in my own configuration section to remove a redundant level of nesting, but I couldn't find how to do it.

1

There are 1 answers

1
competent_tech On BEST ANSWER

You need to decorate your default collection with the appropriate ConfigurationProperty attribute:

[ConfigurationProperty("", Options = ConfigurationPropertyOptions.IsDefaultCollection)]