Ejemplo n.º 1
0
        private static object ReadDictionaryNonGeneric <T>(ReaderState reader)
        {
            var count  = reader.Read <int>();
            var result = CreateDictionaryResultObject <T>(count);

            switch (result)
            {
            case IDictionary d:
            {
                for (var i = 0; i < count; i++)
                {
                    var key   = Deserializer.ReadValue(reader);
                    var value = Deserializer.ReadValue(reader);
                    d.Add(key, value);
                }

                break;
            }

            default:
            {
                for (var i = 0; i < count; i++)
                {
                    Discarder.DiscardValue(reader);     // key
                    Discarder.DiscardValue(reader);     // value
                }

                break;
            }
            }

            return(result);
        }
Ejemplo n.º 2
0
            private static void Populate(object obj, ReaderState reader, IDictionary <string, IMemberSetterHandler <ReaderState> > setterHandlers)
            {
                while (Reader.ReadEnumerableType(reader) == EnumerableType.HasItem)
                {
                    var key = reader.ReadString();
                    if (!setterHandlers.TryGetValue(key, out var setter))
                    {
                        Discarder.DiscardValue(reader);
                        continue;
                    }

                    setter.Handle(reader, obj);
                }
            }
Ejemplo n.º 3
0
        private static object ReadEnumerableNonGeneric <T>(ReaderState reader)
        {
            var result = CreateResultObject <T>();

            if (result is IList l)
            {
                while (Reader.ReadEnumerableType(reader) == EnumerableType.HasItem)
                {
                    l.Add(Deserializer.ReadValue(reader));
                }
            }
            else
            {
                while (Reader.ReadEnumerableType(reader) == EnumerableType.HasItem)
                {
                    Discarder.DiscardValue(reader);
                }
            }

            return(result);
        }
Ejemplo n.º 4
0
        private static object ReadListNonGeneric <T>(ReaderState reader)
        {
            var count  = reader.Read <int>();
            var result = CreateResultObject <T>(count);

            if (result is IList l)
            {
                for (var i = 0; i < count; i++)
                {
                    l.Add(Deserializer.ReadValue(reader));
                }
            }
            else
            {
                for (var i = 0; i < count; i++)
                {
                    Discarder.DiscardValue(reader);
                }
            }

            return(result);
        }