Esempio n. 1
0
        public IList GetListObjects(string listName, string itemName, Type type, DJdConvert convert)
        {
            IList listObjs = null;
            IDictionary jsonMap = json [listName] as IDictionary;
            if (jsonMap != null && jsonMap.Count > 0) {
                IList jsonList = jsonMap [itemName] as IList;
                if (jsonList != null && jsonList.Count > 0) {
                    Type listType = typeof(List<>).MakeGenericType (new Type[] { type });
                    listObjs = Activator.CreateInstance (listType) as IList;
                    foreach (object item in jsonList) {
                        if (typeof(IDictionary).IsAssignableFrom (item.GetType ())) { // object
                            IDictionary subMap = item as IDictionary;
                            object subObj = convert (new JdJsonReader (subMap), type);
                            if (subObj != null) {
                                listObjs.Add (subObj);
                            }
                        } else if (typeof(IList).IsAssignableFrom (item.GetType ())) { // list or array
                            // TODO not support yet
                        } else if (typeof(JsonNumber).IsAssignableFrom (item.GetType ())) { // long
                            listObjs.Add (((JsonNumber)item).ToInt64 ());
                        } else { // string, bool, other
                            listObjs.Add (item);
                        }
                    }
                }
            }

            return listObjs;
        }
Esempio n. 2
0
 public object GetReferenceObject(object name, Type type, DJdConvert convert)
 {
     IDictionary dict = json [name] as IDictionary;
     if (dict != null && dict.Count > 0) {
         return convert (new JdJsonReader (dict), type);
     } else if (json [name].ToString () != null && type.ToString ().EndsWith ("[]")) {
         return Jayrock.Json.Conversion.JsonConvert.Import (type, json [name].ToString ());
     } else {
         return null;
     }
 }
Esempio n. 3
0
        public object GetReferenceObject(object name, Type type, DJdConvert convert)
        {
            IDictionary dict = json [name] as IDictionary;

            if (dict != null && dict.Count > 0)
            {
                return(convert(new JdJsonReader(dict), type));
            }
            else if (json [name].ToString() != null && type.ToString().EndsWith("[]"))
            {
                return(Jayrock.Json.Conversion.JsonConvert.Import(type, json [name].ToString()));
            }
            else
            {
                return(null);
            }
        }
Esempio n. 4
0
        public IList GetListObjects(string listName, string itemName, Type type, DJdConvert convert)
        {
            IList       listObjs = null;
            IDictionary jsonMap  = json [listName] as IDictionary;

            if (jsonMap != null && jsonMap.Count > 0)
            {
                IList jsonList = jsonMap [itemName] as IList;
                if (jsonList != null && jsonList.Count > 0)
                {
                    Type listType = typeof(List <>).MakeGenericType(new Type[] { type });
                    listObjs = Activator.CreateInstance(listType) as IList;
                    foreach (object item in jsonList)
                    {
                        if (typeof(IDictionary).IsAssignableFrom(item.GetType()))                             // object
                        {
                            IDictionary subMap = item as IDictionary;
                            object      subObj = convert(new JdJsonReader(subMap), type);
                            if (subObj != null)
                            {
                                listObjs.Add(subObj);
                            }
                        }
                        else if (typeof(IList).IsAssignableFrom(item.GetType()))                               // list or array
                        // TODO not support yet
                        {
                        }
                        else if (typeof(JsonNumber).IsAssignableFrom(item.GetType()))                               // long
                        {
                            listObjs.Add(((JsonNumber)item).ToInt64());
                        }
                        else                             // string, bool, other
                        {
                            listObjs.Add(item);
                        }
                    }
                }
            }

            return(listObjs);
        }