Ejemplo n.º 1
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (typeof(ISerializable).IsAssignableFrom(objectType))
            {
                ISerializable s = (ISerializable)Activator.CreateInstance(objectType);
                if (s.Unserialize(reader))
                {
                    return(s);
                }
            }
            else if (HasImplementedRawGeneric(objectType, typeof(IList <>)))
            {
                Type t = objectType.GetGenericArguments()[0];
                if (typeof(ISerializable).IsAssignableFrom(t))
                {
                    var result = Activator.CreateInstance(objectType);
                    while (reader.Read())
                    {
                        switch (reader.TokenType)
                        {
                        case JsonToken.StartObject:
                        {
                            var msg = (GetNextObject(reader, true, t, serializer));
                            ((IList)result).Add((ISerializable)msg);
                        }
                        break;

                        case JsonToken.EndArray:
                            return(result);

                        default:
                            break;
                        }
                    }
                    return(null);
                }
                else if (objectType == typeof(List <string>))
                {
                    return(JsonTools.GetNextStringList(reader, false));
                }
                else if (objectType == typeof(List <int>))
                {
                }
            }
            else if (objectType == typeof(Dictionary <string, long>))
            {
                return(JsonTools.GetNetStringLongMap(reader));
            }

            return(null);
        }
Ejemplo n.º 2
0
        static public object GetNextObject(JsonReader reader, bool isInArray, Type type)
        {
            if (!isInArray)
            {
                reader.Read();
            }

            if (type == typeof(List <string>))
            {
                return(GetNextStringList(reader, isInArray));
            }
            ISerializable s = (ISerializable)Activator.CreateInstance(type);

            if (s.Unserialize(reader))
            {
                return(s);
            }
            return(null);
        }