Implicit ConfigurationElementCollection sections

334 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 best solutions below

1
On BEST ANSWER

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

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