0

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.

fearofawhackplanet
  • 52,166
  • 53
  • 160
  • 253

1 Answers1

2

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

[ConfigurationProperty("", Options = ConfigurationPropertyOptions.IsDefaultCollection)]
competent_tech
  • 44,465
  • 11
  • 90
  • 113
  • And then do I use empty string in the indexer as well? e.g. `public DonkeyCollection Donkeys { get { return (DonekyCollection)base[""]; } }` This seems to work but it looks kinda weird. Thanks – fearofawhackplanet Jan 10 '12 at 14:27