static object StringToObjectForNotArray(string thing) { string[] vs = StringTool.SplitWithFormat(thing, ':'); string typ = vs[0].RemoveString(" ", "\n", "\r", "\t", "[", "]"); string typenames = TypeFormat.ToTrueTypeName(typ); int found = thing.IndexOf(':'); string a = thing.Substring(found + 1); switch (typ) { case "char": { a = StringTool.Unescape(a.TakeString('\'', '\'')[0]); break; } case "string": { a = StringTool.Unescape(a.TakeString('\"', '\"')[0]); break; } case "bool": { a = a.Replace(" ", ""); break; } } System.Reflection.MethodInfo method = typeof(Convert).GetMethod("To" + TypeFormat.TypeNameToType(typenames).Name, new Type[] { typeof(string) }); object[] data = new object[] { a }; object get = method.Invoke(null, data); if (typ == "byte") { get = (byte)get; } return(get); }
static object StringToObjectForArray(string thing) { string[] vs = StringTool.SplitWithFormat(thing, ':'); string typ = vs[0].RemoveString(" ", "\n", "\r", "\t", "[", "]"); string typenames = TypeFormat.ToTrueTypeName(typ); Type[] types = new Type[] { TypeFormat.TypeNameToType(typenames) }; int found = thing.IndexOf(':'); if (thing.Substring(found + 1) != "NotThing") { string a = thing.Substring(found + 1).TakeString('{', '}')[0]; if (typ == "byte") { a = a.Replace(" ", ""); return(StringTool.HexToBytes(a)); } else { string[] b = null; if (typ == "object") { b = a.TakeString('{', '}'); for (int i = 0; i < b.Length; i++) { int index = a.IndexOf("{" + b[i] + "}"); a = a.Substring(0, index) + "[" + i + "]" + a.Substring(index + b[i].Length + 2); } string[] bb = StringTool.SplitWithFormat(a, ','); for (int i = 0; i < bb.Length; i++) { for (int ii = 0; ii < b.Length; ii++) { bb[i] = bb[i].Replace("[" + ii + "]", "{" + b[ii] + "}"); } } b = bb; } else { b = StringTool.SplitWithFormat(a, ','); } Type thistype = typeof(List <>).MakeGenericType(types); IList c = (IList)Activator.CreateInstance(thistype); System.Reflection.MethodInfo toarray = thistype.GetMethod("ToArray"); if (typ == "object") { for (int i = 0; i < b.Length; i++) { c.Add(ChuonStringDeserializeToObject(b[i])); } } else { for (int i = 0; i < b.Length; i++) { object[] data = new object[] { b[i] }; switch (typ) { case "char": { data[0] = StringTool.Unescape(b[i].TakeString('\'', '\'')[0]); break; } case "string": { data[0] = StringTool.Unescape(b[i].TakeString('\"', '\"')[0]); break; } case "bool": { data[0] = b[i].Replace(" ", ""); break; } } System.Reflection.MethodInfo method = typeof(Convert).GetMethod("To" + types[0].Name, new Type[] { typeof(string) }); c.Add(method.Invoke(null, data)); } } return(toarray.Invoke(c, null)); } } else { return(Array.CreateInstance(types[0], 0)); } }