Example #1
0
        /// <summary> Read a <c>Type</c> value from the stream. </summary>
        /// <param name="this">The IBinaryTokenStreamReader to read from</param>
        /// <param name="serializationManager">The serialization manager used to resolve type names.</param>
        /// <param name="expected">Expected Type, if known.</param>
        /// <returns>Data from current position in stream, converted to the appropriate output type.</returns>
        private static Type ReadFullTypeHeader(this IBinaryTokenStreamReader @this, SerializationManager serializationManager, Type expected = null)
        {
            var token = @this.ReadToken();

            if (token == SerializationTokenType.ExpectedType)
            {
                return(expected);
            }

            var t = CheckSpecialTypeCode(token);

            if (t != null)
            {
                return(t);
            }

            if (token == SerializationTokenType.SpecifiedType)
            {
#if TRACE_SERIALIZATION
                var tt = ReadSpecifiedTypeHeader();
                Trace("--Read specified type header for type {0}", tt);
                return(tt);
#else
                return(@this.ReadSpecifiedTypeHeader(serializationManager));
#endif
            }

            throw new SerializationException("Invalid '" + token + "'token in input stream where full type header is expected");
        }