// ----- method overrides ------------------------------------

            /// <summary>
            /// Return the deserialized value which this IPofValue
            /// represents.
            /// </summary>
            /// <param name="typeId">
            /// The required Pof type of the returned value or
            /// <see cref="PofConstants.T_UNKNOWN"/> if the type is to be
            /// inferred from the serialized state.
            /// </param>
            /// <returns>
            /// The deserialized value.
            /// </returns>
            /// <exception cref="InvalidCastException">
            /// If the value is incompatible with the specified type.
            /// </exception>
            public override object GetValue(int typeId)
            {
                object value = m_oValue;

                if (value == null)
                {
                    // Return default value for primitives that have been
                    // optimized out of the serialized binary.
                    switch (typeId)
                    {
                    case PofConstants.T_INT16:
                        return((short)0);

                    case PofConstants.T_INT32:
                        return(0);

                    case PofConstants.T_INT64:
                        return(0L);

                    case PofConstants.T_FLOAT32:
                        return((float)0);

                    case PofConstants.T_FLOAT64:
                        return((double)0);

                    case PofConstants.T_BOOLEAN:
                        return(false);

                    case PofConstants.T_OCTET:
                        return((byte)0);

                    case PofConstants.T_CHAR:
                        return((char)0);

                    default:
                        return(null);
                    }
                }

                return(PofReflectionHelper.EnsureType(value, typeId, PofContext));
            }
            /// <summary>
            /// Return the deserialized value which this IPofValue
            /// represents.
            /// </summary>
            /// <param name="typeId">
            /// PofType expected as a result.
            /// </param>
            /// <returns>
            /// The deserialized value.
            /// </returns>
            public virtual object ReadValue(int typeId)
            {
                // Prevent promotion of null to an intrinsic default value.
                if (PofValue.TypeId == PofConstants.V_REFERENCE_NULL)
                {
                    return(ReadValue());
                }

                if (PofValue.IsUniformEncoded)
                {
                    return(base.ReadAsObject(typeId));
                }

                switch (typeId)
                {
                // Return pof "small" values as the specified type
                // because the serialized form has lost knowledge of
                // the original type.
                case PofConstants.T_INT16:
                    return(ReadInt16(0));

                case PofConstants.T_INT32:
                    return(ReadInt32(0));

                case PofConstants.T_INT64:
                    return(ReadInt64(0));

                case PofConstants.T_FLOAT32:
                    return(ReadSingle(0));

                case PofConstants.T_FLOAT64:
                    return(ReadDouble(0));

                case PofConstants.T_BOOLEAN:
                    return(ReadBoolean(0));

                case PofConstants.T_OCTET:
                    return(ReadByte(0));

                case PofConstants.T_CHAR:
                    return(ReadChar(0));

                case PofConstants.T_UNKNOWN:
                    return(ReadValue());

                case PofConstants.T_DATE:
                    return(ReadDate(0));

                case PofConstants.T_ARRAY:
                case PofConstants.T_UNIFORM_ARRAY:
                case PofConstants.T_UNIFORM_SPARSE_ARRAY:
                    object o = ReadValue();
                    if (!o.GetType().IsArray&& !(o is LongSortedList))
                    {
                        throw new InvalidCastException(o.GetType().FullName + "is not an array");
                    }
                    return(o);

                default:
                    return(PofReflectionHelper.EnsureType(ReadValue(), typeId, PofContext));
                }
            }