static string ObjectToStringForArray(int cont, object thing, bool enter) { Array c = (Array)thing; string type = TypeFormat.typelist[Array.IndexOf(TypeFormat.typelist2, thing.GetType().Name)]; string a = ""; if (c.Length > 0) { a += printTab(enter, cont) + "{" + printTab(enter, cont + 1); if (type == "byte[]") { a += StringTool.BytesToHex((byte[])c) + printTab(enter, cont) + "}"; } else { string makestring(string leftright, bool isstringorchar, int index) { if (isstringorchar) { return(leftright + StringTool.Escape(c.GetValue(index).ToString()) + leftright); } else { return(c.GetValue(index).ToString()); } } for (int i = 0; i < c.Length - 1; i++) { if (type == "object[]") { a += ObjectToString(cont + 1, c.GetValue(i), enter) + "," + printTab(enter, cont + 1); } else { a += makestring(type == "char[]" ? "\'" : "\"", type == "char[]" || type == "string[]", i) + "," + printTab(enter, cont + 1); } } if (type == "object[]") { a += ObjectToString(cont + 1, c.GetValue(c.Length - 1), enter) + printTab(enter, cont) + "}"; } else { a += makestring(type == "char[]" ? "\'" : "\"", type == "char[]" || type == "string[]", c.Length - 1) + printTab(enter, cont) + "}"; } } } else { a += "NotThing"; } return(a); }
static string ObjectToString(int cont, object thing, bool enter) { string a = ""; if (thing != null) { string typ = TypeFormat.typelist[Array.IndexOf(TypeFormat.typelist2, thing.GetType().Name)]; a += typ + ":"; if (typ.Contains("[]")) { a += ObjectToStringForArray(cont, thing, enter); } else if (typ == "Dictionary") { Type datatype = thing.GetType(); Type[] Subdatatype = datatype.GetGenericArguments(); IDictionary c = (IDictionary)thing; a += printTab(enter, cont) + "{" + printTab(enter, cont + 1) + TypeFormat.typelist[Array.IndexOf(TypeFormat.typelist2, Subdatatype[0].Name)] + ":" + TypeFormat.typelist[Array.IndexOf(TypeFormat.typelist2, Subdatatype[1].Name)] + ":"; if (c.Count > 0) { Array keys = Array.CreateInstance(Subdatatype[0], c.Keys.Count); Array values = Array.CreateInstance(Subdatatype[1], c.Values.Count); c.Keys.CopyTo(keys, 0); c.Values.CopyTo(values, 0); for (int i = 0; i < c.Count; i++) { a += printTab(enter, cont + 1) + "{" + printTab(enter, cont + 2) + ObjectToString(cont + 2, keys.GetValue(i), enter) + "," + printTab(enter, cont + 2) + ObjectToString(cont + 2, values.GetValue(i), enter) + printTab(enter, cont + 1) + "}"; } } else { a += "NotThing"; } a += printTab(enter, cont) + "}"; } else if (Array.IndexOf(TypeFormat.typelist, typ) != -1) { string makestring(string leftright, bool isstringorchar) { if (isstringorchar) { return(leftright + StringTool.Escape(thing.ToString()) + leftright); } else { return(thing.ToString()); } } a += makestring(typ == "char" ? "\'" : "\"", typ == "char" || typ == "string"); } else { a += thing.ToString(); } } else { a += "null"; } return(a); }