Config file

G

Gas

I am developing a Class library and I want to use config file to store some
of the key-value pairs..

Heard that app.config is not supported by Class library, is it? if so, what
should I do if I need a config file?

Gas
 
P

Peter Rilling

You are right about not directly supporting its own file, but, your library
does have access to the application's configuration file. That means that
as long as those settings are in the app.config file, your library can read
them using the ConfigurationSettings class.

Another alternative might be so that your library is not dependent on the
config file and rather have the settings passed into your library classes by
the application, for instance as constructor parameters.
 
R

Richard Grimes [MVP]

Gas said:
I am developing a Class library and I want to use config file to
store some of the key-value pairs..

Heard that app.config is not supported by Class library, is it? if
so, what should I do if I need a config file?

Config files are associated with the process, not a library:

http://www.grimes.demon.co.uk/dotnet/configFAQ.htm

If your settings are only used by your classes then you can use a separate
configuration file. The easiest way to do this is to create a serializable
class with the key-value pairs as fields, and then use the XmlSerializer
attributes on that class to define the XML for the data. Just before you
first need to read the key-value pairs deserialize the configuration object
from the XML configuration file using XmlSerializer, and when the values on
the configuration object changes use a XmlSerializer to serialize the
configuration object to the XML disk file.

Richard
 

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