Пример #1
0
        public ComData(IJSONable o)
        {
            string rawT = o.GetType().Name;

            DataType = rawT.Replace("`1", "");//rawT.Replace("`1[", "<").Replace("]", ">");
            Value    = o;
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }
Пример #4
0
 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;
     }
 }
Пример #5
0
        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);
        }
Пример #6
0
        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);
            }
        }
Пример #7
0
        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();
        }
Пример #8
0
 bool testJSON(IJSONable obj)
 {
     return(testHelper(new Packet(new ComData(obj))));
 }
Пример #9
0
 public ComData(Request r)
 {
     DataType = REQ_FLAG + r.ToString();
     Value    = null;
 }
Пример #10
0
 public ComData(string msg)
 {
     DataType = STR_FLAG + msg;
     Value    = null;
 }
Пример #11
0
 /// <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()));
 }
Пример #12
0
 public ComData(IJSONable o)
 {
     value    = new IJSONable[] { o };
     dataType = o.GetType().ToString();
 }
Пример #13
0
 public void sendData(IJSONable data)
 {
     sendData(new ComData(data));
 }
Пример #14
0
 public void addObject(string name, IJSONable val)
 {
     addEntry(name, "{\n");
     tabCount++;
     val.addToJSON(this);
 }