Creating a Settings Object, strong typed yet dynamic in nature.

D

DotNetNewbie

Hi,

There are so many 'settings' or configuration options for an
application I am building, and it seems the list gets longer and
longer as time goes on.

Instead of creating a db table named Settings, and creating text/
integer/boolean columns as a new settings comes up during development,
is there a way to just create maybe a XML file or a a different db
table design that I could add new settings as I go, and in the
database store the datatype and somehow this generates a strongly
typed Class?
 
P

Peter

Hi,

There are so many 'settings' or configuration options for an
application I am building, and it seems the list gets longer and
longer as time goes on.

Instead of creating a db table named Settings, and creating text/
integer/boolean columns as a new settings comes up during development,
is there a way to just create maybe a XML file or a a different db
table design that I could add new settings as I go, and in the
database store the datatype and somehow this generates a strongly
typed Class?

Hi

One option is "System.Configuration" Namespace....

An other (I prefere this)
create a class with all Settings
use XML-Serializing to save/load the settings.
benefits:
easy using different settings (serialize/deserialize different
files)
easy editing with PropertyGrid in your App.
easy to protect the settings-File against editing (using
CryptoStream for serialize/deserialize)
Stong typed Settings


Peter
 
I

Ignacio Machin \( .NET/ C# MVP \)

Hi,


I have a similar situation, what I do is using the app.config file to store
my options, this is very easy to edit (it's just a XML file) and it will
have an inmediate effect. In your code they are accesible from all over the
app, also worth to notice is that in 2.0 the Configuration options are very
powerful (and a little too complex IMHO) so you can access your config
option using classes. also there is the possibility to use external files.

Take a look at:
http://www.eggheadcafe.com/tutorial...d-3fbe41b5ce79/creating-an-object-config.aspx
 
K

Kevin Spencer

You can use an XML-serialzable class to store your settings in. Then you can
serialize it and de-serialize it to read them and save them.

--
HTH,

Kevin Spencer
Chicken Salad Surgeon
Microsoft MVP
 

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