Heelana.Com

Settings Class

Version 1.0

About:

The Settings class is written in C# and provides an easy way to store and load application settings/options in an ini-file like structure. The class uses an XML file as its underlying database but hides all the XML details from the user. All data are written/read with a simple interface of functions of the following form:

DataType ReadDataType(string section, string name, DataType defaultValue)

void WriteDataType(string section, string name, DataType value)

Like ini-files the Settings class stores settings in sections which contain name-value pairs. The following example code shows the basic use:

 //read settings
 Settings s = new Settings(“c:\\myprogram\\settings.xml”);

 string lastDir = s.ReadString(“Data1”, “LastDir”, “c:\\”);

 DateTime lastUsage =
 s.ReadDateTime(“Data1”, “LastUsage”, DateTime.Now);
 

 //write settings
 Settings s = new Settings(“c:\\myprogram\\settings.xml”);

 s.WriteString(“Data1”, “LastDir”, lastDir);

 s.WriteDateTime(“Data1”, “LastUsage”, DateTime.Now);

 s.Save();

 The according XML file would look like the following:

 <settings>
   <Data1>
       <LastDir value=”c:\\programs\\” />
       <LastUsage value=”11/03/2003” />
   </Data1>
 </settings>

The class was written with Borlands C#Builder and also tested with SharpDevelop.

For comments/questions please email to mail@heelana.com. Your feedback is very welcome!

Download