////////////////////////////////////////////////////////////// /// <summary> /// Generates a representation of the list using the trace /// string rather than ToString for all list objects. Each /// element in the list will be separated by the specified /// separator string. /// </summary> /// <param name="l">the list</param> /// <param name="sep">the object separator</param> /// <returns>a object representing the contents of the /// list</returns> ////////////////////////////////////////////////////////////// public static object Trace(IList l, string sep) { TraceMessage msg = new TraceMessage("["); int i = 0; int count = l.Count; foreach (object elem in l) { msg.Append(elem); if (++i < count) { msg.Append(sep); } } msg.Append("]"); return(msg); }
////////////////////////////////////////////////////////////// /// <summary> /// This overloaded method takes the object separator /// string. /// </summary> /// <param name="m">the dictionary</param> /// <returns>a object representing the contents of the /// dictionary</returns> ////////////////////////////////////////////////////////////// public static object Trace(IDictionary m, String sep) { TraceMessage buf = new TraceMessage("{ "); int i = 0; int count = m.Keys.Count; foreach (object key in m.Keys) { if (key is string) { buf.Append("'"); buf.Append(key); buf.Append("'"); } else { buf.Append(key); } buf.Append(": "); object val = m[key]; if (val is string) { buf.Append("'"); buf.Append(val); buf.Append("'"); } else { buf.Append(val); } if (++i < count) { buf.Append(sep); } } buf.Append(" }"); return(buf); }