Ejemplo n.º 1
0
        private bool ReadObject(ref Object value)
        {
            if (value == null)
            {
                return(false);
            }

            var obj = Current;

            if (obj == null)
            {
                return(false);
            }

            var map = obj as IDictionary;

            if (map == null)
            {
                return(false);
            }

            var type      = value.GetType();
            var listField = DataHelper.GetClassFields(type);

            if (listField == null)
            {
                return(false);
            }
            for (int i = 0; i < listField.Count; i++)
            {
                var    field = listField[i];
                string name  = field.Name;
                if (!map.Contains(name))
                {
                    continue;
                }

                var val = map[name];

                Type memberType = field.FieldType;
                var  item       = DataHelper.Create(memberType);

                DJsonReader reader = new DJsonReader().Append(val);
                if (!reader.Read(ref item))
                {
                    return(false);
                }

                field.SetValue(value, item);
            }

            return(true);
        }
Ejemplo n.º 2
0
        public bool Read(ref IDictionary value)
        {
            if (value == null)
            {
                return(false);
            }

            var obj = Current;

            if (obj == null)
            {
                return(false);
            }

            var map = obj as IDictionary;

            if (map == null)
            {
                return(false);
            }

            var type       = value.GetType();
            var paramTypes = type.GetGenericArguments();
            var keys       = map.Keys;

            foreach (var item in keys)
            {
                var key       = DataHelper.Create(paramTypes[0]);
                var keyReader = new DJsonReader().Append(item);
                if (!keyReader.Read(ref key))
                {
                    return(false);
                }

                var val       = DataHelper.Create(paramTypes[1]);
                var valReader = new DJsonReader().Append(map[item]);
                if (!valReader.Read(ref val))
                {
                    return(false);
                }
                value.Add(key, val);
            }
            return(true);
        }
Ejemplo n.º 3
0
        public bool Read(ref IList value)
        {
            if (value == null)
            {
                return(false);
            }

            var obj = Current;

            if (obj == null)
            {
                return(false);
            }

            var list = obj as IList;

            if (list == null)
            {
                return(false);
            }

            var type       = value.GetType();
            var paramTypes = type.GetGenericArguments();

            for (var i = 0; i < list.Count; i++)
            {
                var data   = DataHelper.Create(paramTypes[0]);
                var reader = new DJsonReader().Append(list[i]);
                if (!reader.Read(ref data))
                {
                    return(false);
                }
                value.Add(data);
            }
            return(true);
        }