Пример #1
0
        /// <summary>
        /// Deserialize object.
        /// </summary>
        /// <returns>Deserialized object.</returns>
        public T Deserialize <T>()
        {
            int pos = Stream.Position;

            byte hdr = Stream.ReadByte();

            var doDetach = _detach;  // save detach flag into a var and reset so it does not go deeper

            _detach = false;

            switch (hdr)
            {
            case PortableUtils.HdrNull:
                return(default(T));

            case PortableUtils.HdrHnd:
                return(ReadHandleObject <T>(pos));

            case PortableUtils.HdrFull:
                return(ReadFullObject <T>(pos));

            case PortableUtils.TypePortable:
                return(ReadPortableObject <T>(doDetach));
            }

            if (PortableUtils.IsPredefinedType(hdr))
            {
                return(PortableSystemHandlers.ReadSystemType <T>(hdr, this));
            }

            throw new PortableException("Invalid header on deserialization [pos=" + pos + ", hdr=" + hdr + ']');
        }