Ejemplo n.º 1
0
        /// <summary>
        /// Deserializa os dados da instancia.
        /// </summary>
        /// <param name="reader"></param>
        public override void Deserialize(Serialization.IO.CompactReader reader)
        {
            _typeName = new Reflection.TypeName();
            _typeName.Deserialize(reader);
            var length = reader.ReadInt16();
            var values = new object[length];

            for (var i = 0; i < length; i++)
            {
                var type = (PrimitiveTypes)reader.ReadByte();
                values[i] = Deserialize(reader, type);
            }
            SetValues(values);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Deserializa o valor.
        /// </summary>
        /// <param name="reader"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        private object Deserialize(Serialization.IO.CompactReader reader, PrimitiveTypes type)
        {
            switch (type)
            {
            case PrimitiveTypes.Null:
                return(null);

            case PrimitiveTypes.Boolean:
                return(reader.ReadBoolean());

            case PrimitiveTypes.Byte:
                return(reader.ReadByte());

            case PrimitiveTypes.Bytes:
                var length = reader.ReadInt32();
                return(reader.ReadBytes(length));

            case PrimitiveTypes.Char:
                return(reader.ReadChar());

            case PrimitiveTypes.DateTime:
                return(reader.ReadDateTime());

            case PrimitiveTypes.DateTimeOffset:
                return(new DateTimeOffset(reader.ReadInt64(), new TimeSpan(reader.ReadInt64())));

            case PrimitiveTypes.Decimal:
                return(reader.ReadDecimal());

            case PrimitiveTypes.Double:
                return(reader.ReadDouble());

            case PrimitiveTypes.Int16:
                return(reader.ReadInt16());

            case PrimitiveTypes.Int32:
                return(reader.ReadInt32());

            case PrimitiveTypes.Int64:
                return(reader.ReadInt64());

            case PrimitiveTypes.Single:
                return(reader.ReadSingle());

            case PrimitiveTypes.String:
                return(reader.ReadString());
            }
            throw new InvalidOperationException("Invalid PrimitiveType");
        }