1 #region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig
2 /************************************************************************************
4 ' Copyright 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
5 ' Copyright 2000-2002 Philip A. Craig
7 ' This software is provided 'as-is', without any express or implied warranty. In no
8 ' event will the authors be held liable for any damages arising from the use of this
11 ' Permission is granted to anyone to use this software for any purpose, including
12 ' commercial applications, and to alter it and redistribute it freely, subject to the
13 ' following restrictions:
15 ' 1. The origin of this software must not be misrepresented; you must not claim that
16 ' you wrote the original software. If you use this software in a product, an
17 ' acknowledgment (see the following) in the product documentation is required.
19 ' Portions Copyright 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole
20 ' or Copyright 2000-2002 Philip A. Craig
22 ' 2. Altered source versions must be plainly marked as such, and must not be
23 ' misrepresented as being the original software.
25 ' 3. This notice may not be removed or altered from any source distribution.
27 '***********************************************************************************/
36 /// Abstract class representing a hierarchical storage used to hold
37 /// application settings. The actual implementation is left to
38 /// derived classes, and may be based on the registry, isolated
39 /// storage or any other mechanism.
41 public abstract class SettingsStorage : IDisposable
43 #region Instance Variables
46 /// The name of this storage
48 private string storageName;
51 /// The parent storage containing this storage
53 private SettingsStorage parentStorage;
56 #region Construction and Disposal
59 /// Construct a SettingsStorage under a parent storage
61 /// <param name="storageName">Name of the storage</param>
62 /// <param name="parentStorage">The parent which contains the new storage</param>
63 public SettingsStorage( string storageName, SettingsStorage parentStorage )
65 this.storageName = storageName;
66 this.parentStorage = parentStorage;
70 /// Dispose of resources held by this storage
72 public abstract void Dispose();
79 /// The number of settings in this group
81 public abstract int SettingsCount
87 /// The name of the storage
89 public string StorageName
91 get { return storageName; }
95 /// The storage that contains this one
97 public SettingsStorage ParentStorage
99 get { return parentStorage; }
107 /// Find out if a substorage exists
109 /// <param name="name">Name of the child storage</param>
110 /// <returns>True if the storage exists</returns>
111 public abstract bool ChildStorageExists( string name );
114 /// Create a child storage of the same type
116 /// <param name="name">Name of the child storage</param>
117 /// <returns>New child storage</returns>
118 public abstract SettingsStorage MakeChildStorage( string name );
121 /// Clear all settings from the storage - empty storage remains
123 public abstract void Clear();
126 /// Load a setting from the storage.
128 /// <param name="settingName">Name of the setting to load</param>
129 /// <returns>Value of the setting or null</returns>
130 public abstract object LoadSetting( string settingName );
133 /// Load an integer setting from the storage
135 /// <param name="settingName">Name of the setting to load</param>
136 /// <returns>Value of the setting or null</returns>
137 public abstract int LoadIntSetting( string settingName );
140 /// Load a string setting from the storage
142 /// <param name="settingName">Name of the setting to load</param>
143 /// <returns>Value of the setting or null</returns>
144 public abstract string LoadStringSetting( string settingName );
147 /// Load a setting from the storage or return a default value
149 /// <param name="settingName">Name of the setting to load</param>
150 /// <param name="settingName">Value to return if the setting is missing</param>
151 /// <returns>Value of the setting or the default value</returns>
152 public abstract object LoadSetting( string settingName, object defaultValue );
155 /// Load an integer setting from the storage or return a default value
157 /// <param name="settingName">Name of the setting to load</param>
158 /// <param name="settingName">Value to return if the setting is missing</param>
159 /// <returns>Value of the setting or the default value</returns>
160 public abstract int LoadIntSetting( string settingName, int defaultValue );
163 /// Load a string setting from the storage or return a default value
165 /// <param name="settingName">Name of the setting to load</param>
166 /// <param name="settingName">Value to return if the setting is missing</param>
167 /// <returns>Value of the setting or the default value</returns>
168 public abstract string LoadStringSetting( string settingName, string defaultValue );
171 /// Remove a setting from the storage
173 /// <param name="settingName">Name of the setting to remove</param>
174 public abstract void RemoveSetting( string settingName );
177 /// Save a setting in the storage
179 /// <param name="settingName">Name of the setting to save</param>
180 /// <param name="settingValue">Value to be saved</param>
181 public abstract void SaveSetting( string settingName, object settingValue );