using System; using System.Text; using System.Collections; using System.Collections.Specialized; namespace P4API { /// /// Subclass of Hashtable which provides additional methods for dealing with the psuedo-arrays passed from Perforce. /// public class P4Record : Hashtable { internal P4Record(Hashtable sd) { foreach (string s in sd.Keys) { base.Add(s, sd[s]); } } public string[] getArray(string var) { ArrayList al = new ArrayList(); int i = 0; while(base.ContainsKey(var + i.ToString())) { al.Add(base[var + i.ToString()]); i++; } return (string[])al.ToArray(typeof(string[])); } public void setArray(string Variable, string[] ArrayValues) { //First clear any variables that may already exist int i = 0; while (base.ContainsKey(Variable + i.ToString())) { base.Remove(Variable + i.ToString()); i++; } // Now add in all that we need i = 0; foreach (string val in ArrayValues) { base.Add(Variable + i.ToString(), val); i++; } } public override string ToString() { StringBuilder sb = new StringBuilder(); foreach (string s in this.Keys) { sb.Append(String.Format("{0} : {1}\n", s, this[s])); } return sb.ToString(); } /// /// If the underlying P4BaseRecordSet has a key of "var1", it is assumed that this variable is an array, and will return as such. /// public bool isArray(string var) { throw new System.NotImplementedException(); } } }