.NET 2.0 Configuration

  • Thread starter Thread starter Michael Lang
  • Start date Start date
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
 
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.
 
Back
Top