public object[] ReadFromJSONObject(Type t, object jObjs)
        {
            int size;

            if (jObjs is Dictionary <string, object> )
            {
                size = 1;
            }
            else if (jObjs is System.Collections.IList)
            {
                size = (jObjs as System.Collections.IList).Count;
            }
            else if (jObjs.GetType().IsArray)
            {
                size = (jObjs as object[]).Length;
            }
            else
            {
                throw new Exception(
                          @"Wrong json object format.Must be List<Dictionary<stirng,object>> or Dictionary<string,object>.But was " + jObjs.GetType().Name);
            }

            Array objects = Array.CreateInstance(t, size);

            for (int i = 0; i < size; i++)
            {
                objects.SetValue(ReflectionSupport.CreateNewInstance(t), i);
            }

            LoadFromJSONObject(t, jObjs, (object[])objects, 0, size);
            return((object[])objects);
        }
        public T[] ReadFromJSONObject <T>(object jObjs)
        {
            int size;

            if (jObjs is Dictionary <string, object> )
            {
                size = 1;
            }
            else if (jObjs is System.Collections.IList)
            {
                size = (jObjs as System.Collections.IList).Count;
            }
            else if (jObjs.GetType().IsArray)
            {
                size = (jObjs as object[]).Length;
            }
            else
            {
                throw new Exception(
                          @"Wrong json object format.Must be List<Dictionary<stirng,object>> or Dictionary<string,object>.But was " + jObjs.GetType().Name);
            }

            T[] objects = ReflectionSupport.CreateNewInstances <T>(size);
            LoadFromJSONObject <T>(jObjs, objects, 0, size);
            return(objects);
        }
示例#3
0
 public T[] Get <T>(DataTable result, ClassDesc desc)
 {
     T[] objects = ReflectionSupport.CreateNewInstances <T>(result.Rows.Count);
     SetTo(result, 0, desc, objects, 0, objects.Length);
     return(objects);
 }