Example #1
0
        private object ReadRawValue(IEdmPrimitiveTypeReference expectedPrimitiveTypeReference)
        {
            string text = this.textReader.ReadToEnd();

            if ((expectedPrimitiveTypeReference != null) && !base.MessageReaderSettings.DisablePrimitiveTypeConversion)
            {
                return(AtomValueUtils.ConvertStringToPrimitive(text, expectedPrimitiveTypeReference));
            }
            return(text);
        }
        private void WriteRawValue(object value)
        {
            string str;

            if (!AtomValueUtils.TryConvertPrimitiveToString(value, out str))
            {
                throw new ODataException(Microsoft.Data.OData.Strings.ODataUtils_CannotConvertValueToRawPrimitive(value.GetType().FullName));
            }
            this.InitializeTextWriter();
            this.TextWriter.Write(str);
        }
Example #3
0
        /// <summary>
        /// Converts the specified <paramref name="value"/> into its raw format and writes it to the output.
        /// The value has to be of primitive type. Only one WriteRawValue call should be made before this object gets disposed.
        /// </summary>
        /// <param name="value">The (non-binary) value to write.</param>
        /// <remarks>We do not accept binary values here; WriteBinaryValue should be used for binary data.</remarks>
        internal void WriteRawValue(object value)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(!(value is byte[]), "!(value is byte[])");

            string valueAsString;

            if (!AtomValueUtils.TryConvertPrimitiveToString(value, out valueAsString))
            {
                // throw an exception because the value is not primitive
                throw new ODataException(Strings.ODataUtils_CannotConvertValueToRawPrimitive(value.GetType().FullName));
            }

            this.textWriter.Write(valueAsString);
        }
        /// <summary>
        /// Reads the content of a text reader as string and, if <paramref name="expectedPrimitiveTypeReference"/> is specified and primitive type conversion
        /// is enabled, converts the string to the expected type.
        /// </summary>
        /// <param name="expectedPrimitiveTypeReference">The expected type of the value being read or null if no type conversion should be performed.</param>
        /// <returns>The raw value that was read from the text reader either as string or converted to the provided <paramref name="expectedPrimitiveTypeReference"/>.</returns>
        private object ReadRawValue(IEdmPrimitiveTypeReference expectedPrimitiveTypeReference)
        {
            string stringFromStream = this.textReader.ReadToEnd();

            object rawValue;

            if (expectedPrimitiveTypeReference != null && !this.MessageReaderSettings.DisablePrimitiveTypeConversion)
            {
                rawValue = AtomValueUtils.ConvertStringToPrimitive(stringFromStream, expectedPrimitiveTypeReference);
            }
            else
            {
                rawValue = stringFromStream;
            }

            return(rawValue);
        }