PageRenderTime 20ms CodeModel.GetById 13ms app.highlight 4ms RepoModel.GetById 1ms app.codeStats 0ms

/src/NUnit/util/MemorySettingsStorage.cs

#
C# | 79 lines | 50 code | 16 blank | 13 comment | 2 complexity | c7327d3fc17f9d45b55bbd0a42b47d8f MD5 | raw file
 1// ****************************************************************
 2// Copyright 2007, Charlie Poole
 3// This is free software licensed under the NUnit license. You may
 4// obtain a copy of the license at http://nunit.org
 5// ****************************************************************
 6
 7using System;
 8using System.Collections;
 9
10namespace NUnit.Util
11{
12	/// <summary>
13	///  MemorySettingsStorage is used to hold settings for
14	///  the NUnit tests and also serves as the base class
15	///  for XmlSettingsStorage.
16	/// </summary>
17	public class MemorySettingsStorage : ISettingsStorage
18	{
19		protected Hashtable settings = new Hashtable();
20
21		#region ISettingsStorage Members
22
23		public object GetSetting(string settingName)
24		{
25			return settings[settingName];
26		}
27
28		public void RemoveSetting(string settingName)
29		{
30			settings.Remove( settingName );
31		}
32
33		public void RemoveGroup( string groupName )
34		{
35			ArrayList keysToRemove = new ArrayList();
36
37			string prefix = groupName;
38			if ( !prefix.EndsWith(".") )
39				prefix = prefix + ".";
40
41			foreach( string key in settings.Keys )
42				if ( key.StartsWith( prefix ) )
43					keysToRemove.Add( key );
44
45			foreach( string key in keysToRemove )
46				settings.Remove( key );
47		}
48
49		public void SaveSetting(string settingName, object settingValue)
50		{
51			settings[settingName] = settingValue;
52		}
53
54		public ISettingsStorage MakeChildStorage(string name)
55		{
56			return new MemorySettingsStorage();
57		}
58
59		public virtual void LoadSettings()
60		{
61			// No action required
62		}
63
64		public virtual void SaveSettings()
65		{
66			// No action required
67		}
68		#endregion
69
70		#region IDisposable Members
71
72		public void Dispose()
73		{
74			// TODO:  Add MemorySettingsStorage.Dispose implementation
75		}
76
77		#endregion
78	}
79}