public static IDictionary <string, object> ReadObject(ReaderState reader)
        {
            var expandoObject = (IDictionary <string, object>) new ExpandoObject();

            while ((EnumerableType)reader.Read <byte>() == EnumerableType.HasItem)
            {
                var key = reader.ReadString();
                expandoObject[key] = ReadValue(reader);
            }

            return(expandoObject);
        }
Exemple #2
0
                public object Read(ReaderState reader)
                {
                    var result = (IDictionary)activate();

                    while ((EnumerableType)reader.Read <byte>() == EnumerableType.HasItem)
                    {
                        var key   = reader.ReadString();
                        var value = Deserializer.ReadValue(reader);
                        result.Add(key, value);
                    }
                    return(result);
                }
Exemple #3
0
            private static void Populate(object obj, ReaderState reader, IDictionary <string, IMemberSetterHandler <ReaderState> > setterHandlers)
            {
                while ((EnumerableType)reader.Read <byte>() == EnumerableType.HasItem)
                {
                    var key = reader.ReadString();
                    if (!setterHandlers.TryGetValue(key, out var setter))
                    {
                        DiscardValue(reader);
                        continue;
                    }

                    setter.Handle(reader, obj);
                }
            }
Exemple #4
0
        public static void DiscardValue(ReaderState reader, SerializedType?knownType = null)
        {
            var valueType = knownType ?? (SerializedType)reader.Read <byte>();

            switch (valueType)
            {
            case SerializedType.CustomObject:
                DiscardValue(reader);     // custom object ID
                while ((EnumerableType)reader.Read <byte>() == EnumerableType.HasItem)
                {
                    reader.ReadString();     // key
                    DiscardValue(reader);    // value
                }
                break;

            case SerializedType.Object:
                while ((EnumerableType)reader.Read <byte>() == EnumerableType.HasItem)
                {
                    reader.ReadString();     // key
                    DiscardValue(reader);    // value
                }
                break;

            case SerializedType.Dictionary:
                var kvpCount = reader.Read <int>();
                for (var i = 0; i < kvpCount; i++)
                {
                    DiscardValue(reader);     // key
                    DiscardValue(reader);     // value
                }
                break;

            case SerializedType.List:
                var count = reader.Read <int>();
                for (var i = 0; i < count; i++)
                {
                    DiscardValue(reader);
                }
                break;

            case SerializedType.Enumerable:
                while ((EnumerableType)reader.Read <byte>() == EnumerableType.HasItem)
                {
                    DiscardValue(reader);
                }
                break;

            case SerializedType.String:
                Reader.ReadString(reader);
                break;

            case SerializedType.Byte:
                Reader.ReadByte(reader);
                break;

            case SerializedType.SByte:
                Reader.ReadSByte(reader);
                break;

            case SerializedType.UShort:
                Reader.ReadUShort(reader);
                break;

            case SerializedType.Short:
                Reader.ReadShort(reader);
                break;

            case SerializedType.UInt:
                Reader.ReadUInt(reader);
                break;

            case SerializedType.Int:
                Reader.ReadInt(reader);
                break;

            case SerializedType.ULong:
                Reader.ReadULong(reader);
                break;

            case SerializedType.Long:
                Reader.ReadLong(reader);
                break;

            case SerializedType.Float:
                Reader.ReadFloat(reader);
                break;

            case SerializedType.Double:
                Reader.ReadDouble(reader);
                break;

            case SerializedType.Bool:
                Reader.ReadBool(reader);
                break;

            case SerializedType.Decimal:
                Reader.ReadDecimal(reader);
                break;

            case SerializedType.DateTime:
                Reader.ReadDateTime(reader);
                break;

            case SerializedType.Char:
                Reader.ReadChar(reader);
                break;

            case SerializedType.Null:
                break;

            default:
                throw new NotSupportedException($"SerializedType '{valueType}' is not supported");
            }
        }