public IList GetListObjects(string listName, string itemName, Type type, DTopConvert convert)
        {
            IList listObjs = null;

            IList jsonList = json[listName] 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 TopJsonSimplifyReader(subMap), type);
                        if (subObj != null)
                        {
                            listObjs.Add(subObj);
                        }
                    }
                    else if (typeof(IList).IsAssignableFrom(item.GetType())) // list or array
                    {
                        // TODO not support yet
                    }
                    else // string, bool, long, double, null, other
                    {
                        listObjs.Add(item);
                    }
                }
            }

            return listObjs;
        }
 public IList GetListObjects(string listName, string itemName, Type type, DTopConvert convert)
 {
     IList list = null;
     IDictionary dictionary = this.json[listName] as IDictionary;
     if ((dictionary != null) && (dictionary.Count > 0))
     {
         IList list2 = dictionary[itemName] as IList;
         if ((list2 == null) || (list2.Count <= 0))
         {
             return list;
         }
         list = Activator.CreateInstance(typeof(List<>).MakeGenericType(new Type[] { type })) as IList;
         foreach (object obj2 in list2)
         {
             if (typeof(IDictionary).IsAssignableFrom(obj2.GetType()))
             {
                 IDictionary json = obj2 as IDictionary;
                 object obj3 = convert(new TopJsonReader(json), type);
                 if (obj3 != null)
                 {
                     list.Add(obj3);
                 }
             }
             else if (!typeof(IList).IsAssignableFrom(obj2.GetType()))
             {
                 list.Add(obj2);
             }
         }
     }
     return list;
 }
 public object GetReferenceObject(object name, Type type, DTopConvert convert)
 {
     IDictionary json = this.json[name] as IDictionary;
     if ((json != null) && (json.Count > 0))
     {
         return convert(new TopJsonReader(json), type);
     }
     return null;
 }
 public object GetReferenceObject(object name, Type type, DTopConvert convert)
 {
     IDictionary dict = json[name] as IDictionary;
     if (dict != null && dict.Count > 0)
     {
         return convert(new TopJsonReader(dict), type);
     }
     else
     {
         return null;
     }
 }
Exemple #5
0
        public object GetReferenceObject(object name, Type type, DTopConvert convert)
        {
            IDictionary dict = json[name] as IDictionary;

            if (dict != null && dict.Count > 0)
            {
                return(convert(new TopSimplifyJsonReader(dict), type));
            }
            else
            {
                return(null);
            }
        }
Exemple #6
0
        public IList GetListObjects(string listName, string itemName, Type type, DTopConvert 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 TopJsonReader(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);
        }