.NET 2.0 Configuration

M

Michael Lang

Any suggestions on how you can load an arbitrary number of unknown
attributes on an element in a custom section in the .config into a
NameValueCollection ?

Basically I want to do something similiar to what occurs with a
System.Configuration.Provider.ProviderBase Initialise method - the provider
is passed a NameValueCollection containing attribute names and their
associated values from the .config. see...

http://msdn2.microsoft.com/en-us/library/system.configuration.provider.providerbase.initialize.aspx

All the examples I've seen with the .NET 2.0 config api deal with scenarios
where the attributes are predefined and loaded using static code.

One brute force solution that comes to mind is just to by-pass the
Configuration api and use XML/DOM to parse the web config . But if there's
a more elegant solution that leverages the .NET Config API I'd like to use
it.

Thanks in advance

Michael
 
K

Kevin Spencer

What you need to do is to create your own configuration classes which can be
used in conjuntion with your configuration file. The .Net 2.0 Configuration
object model is incredibly extensible, allowing you to store any type of
data serialized in configuration files.

The System.Configuration Namespace is the location of all of these classes
(http://msdn2.microsoft.com/en-us/library/system.configuration.aspx). The
most salient ones are Configuration, ConfigurationManager,
ConfigurationElement, ConfigurationElementCollection, ConfigurationSection,
ConfigurationSectionCollection, ConfigurationSectionGroup, and
ConfigurationSectionGroupCollection. These are the classes that correspond
to the various XML elements in a Configuration file. Once you define your
classes, you can use them in any Configuration file.

--
HTH,

Kevin Spencer
Microsoft MVP
Software Composer
http://unclechutney.blogspot.com

In case of Minimalism, break Philip Glass.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top