Home All Groups Group Topic Archive Search About

How to use multiple elements in a configuration collection

Author
5 Jan 2007 10:48 AM
Ramon de Klein
I want to use a ConfigurationElementCollection that contains elements of
different types. The following code is an example of what I would like:

  <output>
   <ftp server="ftp://www.foo.com" file="test1.xml"/>
   <ftp server="ftp://www.foo.com" file="test2.xml"/>
   <email address="j***@foo.com" file="test2.xml"/>
  </output>

I haven't found a method to use different ConfigurationElement derived
classes in the same collection. Is this possible? I think I have to do some
manual (de)serialization, but before I investigate that I want to make sure
there is no easier way. Thanks for your support...

Author
5 Jan 2007 12:35 PM
Kevin Spencer
Hi Ramon,

You can create a custom ConfigurationSection-derived class that contains a
number of different custom ConfigurationElement-derived class instances, but
these must be pre-defined as members in the ConfigurationSection. For
example, you could not specifiy that the ConfigurationSection contained a
variable numbe of "ftp" ConfigurationElements , but only a certain number of
them, and a certain number of "email" elements. However, it *can* contain a
fixed number of ConfigurationElementCollection-derived elements, each of
which may contain a variable number of a specific type of
ConfigurationElement items. So, if you use the Collections method, you can
define ConfigurationSection classes that define a number of specific
ConfigurationElementCollection instances, each of which may have 0 or more
ConfigurationElement instances in it.

--
HTH,

Kevin Spencer
Microsoft MVP
Bit Player
http://unclechutney.blogspot.com

Where there's a Will, there's a William.

Show quote
"Ramon de Klein" <RamondeKl***@discussions.microsoft.com> wrote in message
news:7B21FEF6-46A6-4EB7-AEDE-5185CCED7C15@microsoft.com...
>I want to use a ConfigurationElementCollection that contains elements of
> different types. The following code is an example of what I would like:
>
>  <output>
>   <ftp server="ftp://www.foo.com" file="test1.xml"/>
>   <ftp server="ftp://www.foo.com" file="test2.xml"/>
>   <email address="j***@foo.com" file="test2.xml"/>
>  </output>
>
> I haven't found a method to use different ConfigurationElement derived
> classes in the same collection. Is this possible? I think I have to do
> some
> manual (de)serialization, but before I investigate that I want to make
> sure
> there is no easier way. Thanks for your support...

AddThis Social Bookmark Button