#region Copyright (c) 2002-2003, James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole, Philip A. Craig /************************************************************************************ ' ' Copyright 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole ' Copyright 2000-2002 Philip A. Craig ' ' This software is provided 'as-is', without any express or implied warranty. In no ' event will the authors be held liable for any damages arising from the use of this ' software. ' ' Permission is granted to anyone to use this software for any purpose, including ' commercial applications, and to alter it and redistribute it freely, subject to the ' following restrictions: ' ' 1. The origin of this software must not be misrepresented; you must not claim that ' you wrote the original software. If you use this software in a product, an ' acknowledgment (see the following) in the product documentation is required. ' ' Portions Copyright 2002-2003 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov, Charlie Poole ' or Copyright 2000-2002 Philip A. Craig ' ' 2. Altered source versions must be plainly marked as such, and must not be ' misrepresented as being the original software. ' ' 3. This notice may not be removed or altered from any source distribution. ' '***********************************************************************************/ #endregion namespace NUnit.Util { using System; using System.Collections; /// /// SettingsGroup is the base class representing a group /// of user or system settings. A pimpl idiom is used /// to provide implementation-independence. /// public class SettingsGroup : IDisposable { #region Instance Variables /// /// The name of this group of settings /// private string name; /// /// If not null, the storage implementation holding the group settings. /// private SettingsStorage storageImpl; /// /// If not null, the settings group that contains this one. /// private SettingsGroup parentSettings; #endregion #region Construction and Disposal /// /// Construct a settings group based on a storage implementation. /// /// Name of the group /// Storage for the group settings public SettingsGroup( string name, SettingsStorage storageImpl ) { this.name = name; this.storageImpl = storageImpl; } /// /// Construct a settings group based on a parent group that contains it. /// /// Name of the group /// Containing group public SettingsGroup( string name, SettingsGroup parentSettings ) { this.name = name; this.parentSettings = parentSettings; this.storageImpl = parentSettings.Storage.MakeChildStorage( name ); } /// /// Dispose of this group by disposing of it's storage implementation /// public void Dispose() { if ( storageImpl != null ) { storageImpl.Dispose(); storageImpl = null; } } #endregion #region Properties /// /// The name of the group /// public string Name { get { return name; } } /// /// The storage used for the group settings /// public SettingsStorage Storage { get { return storageImpl; } } /// /// The number of settings in this group /// public int SettingsCount { get { return storageImpl.SettingsCount; } } #endregion #region Methods /// /// Clear all settings and subgroups in this group /// public virtual void Clear() { storageImpl.Clear(); } /// /// Load the value of one of the group's settings /// /// Name of setting to load /// Value of the setting or null public object LoadSetting( string settingName ) { return storageImpl.LoadSetting( settingName ); } /// /// Load the value of one of the group's integer settings /// in a type-safe manner. /// /// Name of setting to load /// Value of the setting or null public int LoadIntSetting( string settingName ) { return storageImpl.LoadIntSetting( settingName ); } /// /// Load the value of one of the group's string settings /// in a type-safe manner. /// /// Name of setting to load /// Value of the setting or null public string LoadStringSetting( string settingName ) { return storageImpl.LoadStringSetting( settingName ); } /// /// Load the value of one of the group's settings or return a default value /// /// Name of setting to load /// Value to return if the seeting is not present /// Value of the setting or the default public object LoadSetting( string settingName, object defaultValue ) { return storageImpl.LoadSetting( settingName, defaultValue ); } /// /// Load the value of one of the group's integer settings /// in a type-safe manner or return a default value /// /// Name of setting to load /// Value to return if the seeting is not present /// Value of the setting or the default public int LoadIntSetting( string settingName, int defaultValue ) { return storageImpl.LoadIntSetting( settingName, defaultValue ); } /// /// Load the value of one of the group's string settings /// in a type-safe manner or return a default value /// /// Name of setting to load /// Value to return if the seeting is not present /// Value of the setting or the default public string LoadStringSetting( string settingName, string defaultValue ) { return storageImpl.LoadStringSetting( settingName, defaultValue ); } /// /// Remove a setting from the group /// /// Name of the setting to remove public void RemoveSetting( string settingName ) { storageImpl.RemoveSetting( settingName ); } /// /// Save the value of one of the group's settings /// /// Name of the setting to save /// Value to be saved public void SaveSetting( string settingName, object settingValue ) { storageImpl.SaveSetting( settingName, settingValue ); } /// /// Save the value of one of the group's integer settings /// in a type-safe manner. /// /// Name of the setting to save /// Value to be saved public void SaveIntSetting( string settingName, int settingValue ) { storageImpl.SaveSetting( settingName, settingValue ); } /// /// Save the value of one of the group's string settings /// in a type-safe manner. /// /// Name of the setting to save /// Value to be saved public void SaveStringSetting( string settingName, string settingValue ) { storageImpl.SaveSetting( settingName, settingValue ); } #endregion } }