public ComData(IJSONable o) { string rawT = o.GetType().Name; DataType = rawT.Replace("`1", "");//rawT.Replace("`1[", "<").Replace("]", ">"); Value = o; }
public static List <T> ObjectsFromListFromFactory <T>(List <object> list, FactoryCreateMethod method) { List <T> result = new List <T>(); if (list == null) { return(result); } foreach (var item in list) { IDictionary itemDict = item as IDictionary; string id = itemDict["id"].ToString(); T obj = (T)method(id); IJSONable asJsonable = obj as IJSONable; if (asJsonable != null) { asJsonable.FromDict(itemDict); result.Add(obj); } else { Debug.LogError("ObjectsFromListFromFactory parse error: " + id); } } return(result); }
public static T ObjectFromDict <T>(IDictionary dict) { T newObj = (T)Activator.CreateInstance(typeof(T)); if (dict != null && dict.Count > 0) { IJSONable asJsonable = newObj as IJSONable; asJsonable.FromDict(dict); } return(newObj); }
public void fillFromJSON(JSONDecoder jd) { //jd.SkipLine(); DataType = jd.ParseNext((s) => { return(s.Substring(1, s.Length - 2)); }); if (DataType.StartsWith(PRIM)) { Value = null; return; } else { RawValue = jd; } }
public static Dictionary <string, T> ObjectsFromDictFromFactory <T>(IDictionary dict, FactoryCreateMethod method) { Dictionary <string, T> result = new Dictionary <string, T>(); foreach (object e in dict.Keys) { string id = e.ToString(); result[id] = (T)method(id); IJSONable asJsonable = result[id] as IJSONable; asJsonable.FromDict(dict[e] as IDictionary); } return(result); }
public bool TryParse <T>(ref T container) { JSONDecoder jd = RawValue.Clone(); try { IJSONable raw = (IJSONable)container; raw.fillFromJSON(jd); container = (T)raw; return(true); } catch (Exception) { return(false); } }
public void fillFromJSON(JSONDecoder jd) { jd.beginItem(); dataType = jd.getField()[1]; // dataType jd.getField(); // data jd.beginItem(); // [ Type t = Type.GetType(dataType); Queue <IJSONable> dataQ = new Queue <IJSONable>(); while (!jd.peekLine().Contains("]")) { IJSONable obj = (IJSONable)Activator.CreateInstance(t); obj.fillFromJSON(jd); dataQ.Enqueue(obj); } value = dataQ.ToArray(); jd.endItem(); jd.endItem(); }
bool testJSON(IJSONable obj) { return(testHelper(new Packet(new ComData(obj)))); }
public ComData(Request r) { DataType = REQ_FLAG + r.ToString(); Value = null; }
public ComData(string msg) { DataType = STR_FLAG + msg; Value = null; }
/// <summary> /// Making an HTTP POST request (Async result). /// </summary> /// <param name="endpoint">The URL to send the request to</param> /// <param name="jsonable">An arguments object to send as JSON string</param> /// <returns></returns> public static async Task <string> POST(string endpoint, IJSONable jsonable) { return(await POST(endpoint, jsonable.ToJSON())); }
public ComData(IJSONable o) { value = new IJSONable[] { o }; dataType = o.GetType().ToString(); }
public void sendData(IJSONable data) { sendData(new ComData(data)); }
public void addObject(string name, IJSONable val) { addEntry(name, "{\n"); tabCount++; val.addToJSON(this); }