Introduction
This class is very simple. It provides an easy way to persist key/value pairs between application occurances. It stores the pairs in an XmlDocument
in IsolatedStorage. It is commented for IntelliSense and should be easy to use without much explanation.
Downloads
VisualStudio Solution
The source code is available in the attached solution, containing three projects. The first project is of course the class library that contains one class, ApplicationSettings
, that resides in the VastAbyss.Configuration
namespace.
One project is a simple Console application that I wrote to include in the source of the main project as an XML comment example. When it executes, it creates an instance of ApplicationSettings
. On first run, a new file will be created and the default string will be displayed in the console. The application then takes input from the user and exits. The next time the application runs, it will display the string that was entered the last time; demonstrating that the setting was persisted.
The last project is a Windows application that shows some more use of the class to persist WindowState, Height, Width, and the Text value of some Labels. The on-going theme here is simple persistence, not of user data, but of application settings.
Compiled Class Library Assembly
This download contains only the compiled dll that is needed to be referenced in using the class in a project. I removed all but the source, project, and solution files from the solution before compressing it to keep the size small for your convenience so the I'm including this so you don't have to compile it yourself. The class should be usable and self explanatory without downloading the source code or examples.
Usage
ApplicationSettings appSettings = new ApplicationSettings();
appSettings.ClearSettings();
bool success = appSettings.SetValue("ApplicationTitle", "My Application");
HashTable hTable = appSettings.GetSettings();
string appTitle = appSettings.GetValue("ApplicationTitle");
XmlDocument xmlDoc = appSettings.XmlDocument;
success = appSettings.RemoveValue("ApplicationTitle");
appSettings.SaveConfiguration();
appSettings.Dispose();
Future Plans
I do not have plans to extend the class at this time, but I do have some ideas on how it could be easily extended to be more powerful. I would be worried about destroying the simplicity of the class as it is now, but one of the things that would make it more powerful without being overwhelming would be to add a constructor that takes an enum. For example StorageType.IsolatedStorage
, StorageType.ApplicationData
, StorageType.CurrentDirectory
, StorageType.Registry
, etc... and a constructor that simply takes a file name.
My feeling on this class is that it needs to remain simple. It is designed to fill a niche: an easy way to persist application state for applications that do not require complex settings or user data storage. As seen in the Windows test project, it can fill that niche without many lines of code.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.