Click here to Skip to main content
15,895,746 members
Articles / Programming Languages / C#

TSWizard - A Wizard Framework for .NET

Rate me:
Please Sign up or sign in to vote.
4.86/5 (55 votes)
26 May 2003BSD17 min read 465.8K   4.6K   209  
Provides a framework for creating wizards for use in your .NET applications
using System;
using System.Collections;
using System.Runtime.InteropServices;

namespace TSWizards
{
	public class WizardStepDictionary : IDictionary, ICollection, IEnumerable, ICloneable
	{
		protected Hashtable innerHash;
		
		#region "Constructors"
		public WizardStepDictionary()
		{
			innerHash = new Hashtable();
		}
		public WizardStepDictionary(WizardStepDictionary original)
		{
			innerHash = new Hashtable (original.innerHash);
		}
		public WizardStepDictionary(IDictionary dictionary)
		{
			innerHash = new Hashtable (dictionary);
		}

		public WizardStepDictionary(int capacity)
		{
			innerHash = new Hashtable(capacity);
		}
		#endregion

		#region Implementation of IDictionary
		public WizardStepDictionaryEnumerator GetEnumerator()
		{
			return new WizardStepDictionaryEnumerator(this);
		}
		System.Collections.IDictionaryEnumerator IDictionary.GetEnumerator()
		{
			return new WizardStepDictionaryEnumerator(this);
		}
		IEnumerator IEnumerable.GetEnumerator()
		{
			return GetEnumerator();
		}

		public void Remove(string key)
		{
			innerHash.Remove (key);
		}
		void IDictionary.Remove(object key)
		{
			Remove ((string)key);
		}

		public bool Contains(string key)
		{
			return innerHash.Contains(key);
		}
		bool IDictionary.Contains(object key)
		{
			return Contains((string)key);
		}

		public void Clear()
		{
			innerHash.Clear();		
		}

		public void Add(string key, BaseStep value)
		{
			innerHash.Add (key, value);
		}
		void IDictionary.Add(object key, object value)
		{
			Add ((string)key, (BaseStep)value);
		}

		public bool IsReadOnly
		{
			get
			{
				return innerHash.IsReadOnly;
			}
		}

		public BaseStep this[string key]
		{
			get
			{
				return (BaseStep) innerHash[key];
			}
			set
			{
				innerHash[key] = value;
			}
		}
		object IDictionary.this[object key]
		{
			get
			{
				return this[(string)key];
			}
			set
			{
				this[(string)key] = (BaseStep)value;
			}
		}
        
		public System.Collections.ICollection Values
		{
			get
			{
				return innerHash.Values;
			}
		}

		public System.Collections.ICollection Keys
		{
			get
			{
				return innerHash.Keys;
			}
		}

		public bool IsFixedSize
		{
			get
			{
				return innerHash.IsFixedSize;
			}
		}
		#endregion

		#region Implementation of ICollection
		public void CopyTo(System.Array array, int index)
		{
			innerHash.CopyTo (array, index);
		}

		public void CopyTo(WizardStepDictionary wsc, int index)
		{
			IEnumerator keys = Keys.GetEnumerator();
			IEnumerator values = Values.GetEnumerator();

			int count = Count;

			for(int i = 0; i < index; i++)
			{
				keys.MoveNext();
				values.MoveNext();
			}

			for(int i = index; i < count; i++)
			{
				keys.MoveNext();
				values.MoveNext();

				wsc.Add( keys.Current as string, values.Current as BaseStep );
			}
		}

		public bool IsSynchronized
		{
			get
			{
				return innerHash.IsSynchronized;
			}
		}

		public int Count
		{
			get
			{
				return innerHash.Count;
			}
		}

		public object SyncRoot
		{
			get
			{
				return innerHash.SyncRoot;
			}
		}
		#endregion

		#region Implementation of ICloneable
		public WizardStepDictionary Clone()
		{
			WizardStepDictionary clone = new WizardStepDictionary();
			clone.innerHash = (Hashtable) innerHash.Clone();
			
			return clone;
		}
		object ICloneable.Clone()
		{
			return Clone();
		}
		#endregion
		
		#region "HashTable Methods"
		public bool ContainsKey (string key)
		{
			return innerHash.ContainsKey(key);
		}
		public bool ContainsValue (BaseStep value)
		{
			return innerHash.ContainsValue(value);
		}

		public WizardStepDictionary Synchronized()
		{
			WizardStepDictionary sync = new WizardStepDictionary();
			sync.innerHash = Hashtable.Synchronized(innerHash);

			return sync;
		}
		#endregion

		public class WizardStepDictionaryEnumerator : IDictionaryEnumerator
		{
			private IDictionaryEnumerator innerEnumerator;
			
			internal WizardStepDictionaryEnumerator(WizardStepDictionary enumerable)
			{
				innerEnumerator = enumerable.innerHash.GetEnumerator();
			}

			#region Implementation of IDictionaryEnumerator
			public string Key
			{
				get
				{
					return (string)innerEnumerator.Key;
				}
			}
			object IDictionaryEnumerator.Key
			{
				get
				{
					return Key;
				}
			}


			public BaseStep Value
			{
				get
				{
					return (BaseStep)innerEnumerator.Value;
				}
			}
			object IDictionaryEnumerator.Value
			{
				get
				{
					return Value;
				}
			}

			public System.Collections.DictionaryEntry Entry
			{
				get
				{
					return innerEnumerator.Entry;
				}
			}

			#endregion

			#region Implementation of IEnumerator
			public void Reset()
			{
				innerEnumerator.Reset();
			}

			public bool MoveNext()
			{
				return innerEnumerator.MoveNext();
			}

			object IEnumerator.Current
			{
				get
				{
					return innerEnumerator.Current;
				}
			}

			public DictionaryEntry Current
			{
				get
				{
					return Entry;
				}
			}
			#endregion
		}
	}

}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The BSD License


Written By
Software Developer (Senior) InfoPlanIT, LLC
United States United States
James has been programming in C/C++ since 1998, and grew fond of databases in 1999. His latest interest has been in C# and .NET where he has been having fun writing code starting when .NET v1.0 was in its first beta.

He is currently a senior developer and consultant for InfoPlanIT, a small international consulting company that focuses on custom solutions and business intelligence applications.

He was previously employed by ComponentOne where he was a Product Manager for the ActiveReports, Data Dynamics Reports, and ActiveAnalysis products.

Code contained in articles where he is the sole author is licensed via the new BSD license.

Comments and Discussions