コード例 #1
0
        /// <summary>
        /// Converts the specified <paramref name="value"/> into its raw format and writes it to the output.
        /// The value has to be of enumeration or 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)
        {
            Debug.Assert(!(value is byte[]), "!(value is byte[])");

            string         valueAsString;
            ODataEnumValue enumValue = value as ODataEnumValue;

            if (enumValue != null)
            {
                this.textWriter.Write(enumValue.Value);
            }
            else if (value is Geometry || value is Geography)
            {
                PrimitiveConverter.Instance.TryWriteAtom(value, textWriter);
            }
            else if (AtomValueUtils.TryConvertPrimitiveToString(value, out valueAsString))
            {
                this.textWriter.Write(valueAsString);
            }
            else
            {
                // throw an exception because the value is neither enum nor primitive
                throw new ODataException(Strings.ODataUtils_CannotConvertValueToRawString(value.GetType().FullName));
            }
        }