/// <summary>
        /// Formats the literal without a type prefix, quotes, or escaping.
        /// </summary>
        /// <param name="value">The non-null value to format.</param>
        /// <returns>The formatted literal, without type marker or quotes.</returns>
        private static string FormatRawLiteral(object value)
        {
            Debug.Assert(value != null, "value != null");

            string stringValue = value as string;

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

            if (value is bool)
            {
                return(XmlConvert.ToString((bool)value));
            }

            if (value is byte)
            {
                return(XmlConvert.ToString((byte)value));
            }

#if ASTORIA_SERVER
            if (value is DateTime)
            {
                // Since the server/client supports DateTime values, convert the DateTime value
                // to DateTimeOffset and use XmlCOnvert to convert to String.
                DateTimeOffset dto = WebUtil.ConvertDateTimeToDateTimeOffset((DateTime)value);
                return(XmlConvert.ToString(dto));
            }
#endif

            if (value is decimal)
            {
                return(XmlConvert.ToString((decimal)value));
            }

            if (value is double)
            {
                string formattedDouble = XmlConvert.ToString((double)value);
                formattedDouble = SharedUtils.AppendDecimalMarkerToDouble(formattedDouble);
                return(formattedDouble);
            }

            if (value is Guid)
            {
                return(value.ToString());
            }

            if (value is short)
            {
                return(XmlConvert.ToString((Int16)value));
            }

            if (value is int)
            {
                return(XmlConvert.ToString((Int32)value));
            }

            if (value is long)
            {
                return(XmlConvert.ToString((Int64)value));
            }

            if (value is sbyte)
            {
                return(XmlConvert.ToString((SByte)value));
            }

            if (value is float)
            {
                return(XmlConvert.ToString((Single)value));
            }

            byte[] array = value as byte[];
            if (array != null)
            {
                return(ConvertByteArrayToKeyString(array));
            }

            if (value is DateTimeOffset)
            {
                return(XmlConvert.ToString((DateTimeOffset)value));
            }

            if (value is TimeSpan)
            {
                return(EdmValueWriter.DurationAsXml((TimeSpan)value));
            }

            Geography geography = value as Geography;
            if (geography != null)
            {
                return(WellKnownTextSqlFormatter.Create(true).Write(geography));
            }

            Geometry geometry = value as Geometry;
            if (geometry != null)
            {
                return(WellKnownTextSqlFormatter.Create(true).Write(geometry));
            }

            throw SharedUtils.CreateExceptionForUnconvertableType(value);
        }
Esempio n. 2
0
        /// <summary>
        /// Formats the literal without a type prefix, quotes, or escaping.
        /// </summary>
        /// <param name="value">The non-null value to format.</param>
        /// <returns>The formatted literal, without type marker or quotes.</returns>
        private static string FormatRawLiteral(object value)
        {
            Debug.Assert(value != null, "value != null");

            string stringValue = value as string;

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

            if (value is bool)
            {
                return(XmlConvert.ToString((bool)value));
            }

            if (value is byte)
            {
                return(XmlConvert.ToString((byte)value));
            }

            if (value is DateTime)
            {
#if PORTABLELIB
                return(PlatformHelper.ConvertDateTimeToString((DateTime)value));
#else
                return(XmlConvert.ToString((DateTime)value, XmlDateTimeSerializationMode.RoundtripKind));
#endif
            }

            if (value is decimal)
            {
                return(XmlConvert.ToString((decimal)value));
            }

            if (value is double)
            {
                string formattedDouble = XmlConvert.ToString((double)value);
                formattedDouble = SharedUtils.AppendDecimalMarkerToDouble(formattedDouble);
                return(formattedDouble);
            }

            if (value is Guid)
            {
                return(value.ToString());
            }

            if (value is short)
            {
                return(XmlConvert.ToString((Int16)value));
            }

            if (value is int)
            {
                return(XmlConvert.ToString((Int32)value));
            }

            if (value is long)
            {
                return(XmlConvert.ToString((Int64)value));
            }

            if (value is sbyte)
            {
                return(XmlConvert.ToString((SByte)value));
            }

            if (value is float)
            {
                return(XmlConvert.ToString((Single)value));
            }

            byte[] array = value as byte[];
            if (array != null)
            {
                return(ConvertByteArrayToKeyString(array));
            }

            if (value is DateTimeOffset)
            {
                return(XmlConvert.ToString((DateTimeOffset)value));
            }

            if (value is TimeSpan)
            {
                return(XmlConvert.ToString((TimeSpan)value));
            }

            Geography geography = value as Geography;
            if (geography != null)
            {
                return(WellKnownTextSqlFormatter.Create(true).Write(geography));
            }

            Geometry geometry = value as Geometry;
            if (geometry != null)
            {
                return(WellKnownTextSqlFormatter.Create(true).Write(geometry));
            }

            throw SharedUtils.CreateExceptionForUnconvertableType(value);
        }