/// <summary> /// Returns a string representation of both <see cref="IDictionary"/>s highlighting differences in array elements /// </summary> /// <param name="dict"></param> /// <param name="dict2"></param> /// <param name="prefix"></param> /// <returns></returns> public static string AsciiArt(IDictionary dict, IDictionary dict2, string prefix = "") { var sb = new StringBuilder(); List <object> keys1 = dict.Keys.Cast <object>().OrderBy(i => i).ToList(); List <object> keys2 = dict2.Keys.Cast <object>().OrderBy(i => i).ToList(); for (var i = 0; i < Math.Max(keys1.Count, keys2.Count); i++) { sb.Append(prefix + "[" + i + "] - "); //if run out of values in dictionary 1 if (i > keys1.Count) { sb.AppendLine(string.Format(" {0} - \t <NULL> \t {1}", keys2[i], dict2[keys2[i]])); } //if run out of values in dictionary 2 else if (i > keys2.Count) { sb.AppendLine(string.Format(" {0} - \t {1} \t <NULL>", keys1[i], dict[keys1[i]])); } else { object val1 = dict[keys1[i]]; object val2 = dict2[keys2[i]]; if (val1 is Array && val2 is Array) { sb.Append(string.Format(" {0} : \r\n {1}", keys1[i], ArrayHelperMethods.AsciiArt((Array)val1, (Array)val2, prefix + "\t"))); } else //if both are dictionaries if (IsDictionary(val1) && IsDictionary(val2)) { sb.Append(string.Format(" {0} : \r\n {1}", keys1[i], AsciiArt((IDictionary)val1, (IDictionary)val2, prefix + "\t"))); } else { //if we haven't outrun of either array sb.AppendLine(string.Format(" {0} - \t {1} \t {2} {3}", keys1[i], dict[keys1[i]], dict2[keys2[i]], FlexibleEquality.FlexibleEquals(dict[keys1[i]], dict2[keys2[i]]) ? "" : "<DIFF>")); } } } return(sb.ToString()); }
/// <summary> /// Returns a string representation of the <paramref name="dict"/> suitable for human visualisation /// </summary> /// <param name="dict"></param> /// <param name="prefix"></param> /// <returns></returns> public static string AsciiArt(IDictionary dict, string prefix = "") { var sb = new StringBuilder(); List <object> keys1 = dict.Keys.Cast <object>().OrderBy(i => i).ToList(); for (var i = 0; i < keys1.Count; i++) { sb.Append(prefix); //if run out of values in dictionary 1 object val = dict[keys1[i]]; if (val is Array) { sb.Append(string.Format(" {0} : \r\n {1}", keys1[i], ArrayHelperMethods.AsciiArt((Array)val, prefix + "\t"))); } else //if both are dictionaries if (IsDictionary(val)) { sb.Append(string.Format(" {0} : \r\n {1}", keys1[i], AsciiArt((IDictionary)val, prefix + "\t"))); } else { //if we haven't outrun of either array sb.AppendLine(string.Format(" {0} - \t {1}", keys1[i], val)); } } return(sb.ToString()); }