// // // // // $Revision: 2285 $ // using System; using System.Collections; using System.Collections.Generic; namespace Debugger { /// /// An enumerable collection of values accessible by name. /// public class NamedValueCollection: DebuggerObject, IEnumerable, IEnumerable { internal static NamedValueCollection Empty = new NamedValueCollection(new NamedValue[0]); List list = new List(); Dictionary> hashtable = new Dictionary>(); IEnumerator IEnumerable.GetEnumerator() { foreach(NamedValue namedValue in list) { yield return namedValue; } } IEnumerator IEnumerable.GetEnumerator() { foreach(NamedValue namedValue in list) { yield return namedValue; } } internal NamedValueCollection(IEnumerable namedValues) { foreach(NamedValue namedValue in namedValues) { string name = namedValue.Name; if (hashtable.ContainsKey(name)) { hashtable[name].Add(namedValue); } else { hashtable[name] = new List(new NamedValue[] {namedValue}); } list.Add(namedValue); } } /// /// Gets a value indicating whether the collection contains a /// value with a given name /// public bool Contains(string name) { return hashtable.ContainsKey(name); } /// /// Gets number of named values contained in the collection /// public int Count { get { return list.Count; } } /// /// Gets a value by index /// public NamedValue this[int i] { get { return list[i]; } } /// /// Gets a value by its name. /// public NamedValue this[string variableName] { get { if (hashtable.ContainsKey(variableName)) { foreach(NamedValue namedValue in hashtable[variableName]) { return namedValue; } } // int index = variableName.IndexOf('.'); // if (index != -1) { // string rootVariable = variableName.Substring(0, index); // string subVariable = variableName.Substring(index + 1); // return this[rootVariable].Value.SubVariables[subVariable]; // } throw new DebuggerException("Variable \"" + variableName + "\" is not in collection"); } } } }