/// <summary> /// Write a float value. /// </summary> /// <param name="writer">The text writer to write the output to.</param> /// <param name="value">Float value to be written.</param> internal static void WriteValue(TextWriter writer, float value) { Debug.Assert(writer != null, "writer != null"); if (float.IsInfinity(value) || float.IsNaN(value)) { JsonValueUtils.WriteQuoted(writer, value.ToString(JsonValueUtils.ODataNumberFormatInfo)); } else { // float.ToString() supports a max scale of six, // whereas float.MinValue and float.MaxValue have 8 digits scale. Hence we need // to use XmlConvert in all other cases, except infinity writer.Write(XmlConvert.ToString(value)); } }
internal static void WriteValue(TextWriter writer, DateTimeOffset value, ODataJsonDateTimeFormat dateTimeFormat) { Debug.Assert(writer != null, "writer != null"); Int32 offsetMinutes = (Int32)value.Offset.TotalMinutes; switch (dateTimeFormat) { case ODataJsonDateTimeFormat.ISO8601DateTime: { // Uses the same format as DateTime but with offset: // jsonDateTime= quotation-mark // YYYY-MM-DDThh:mm:ss.sTZD // [("+" / "-") offset] // quotation-mark // // offset = 4DIGIT string textValue = XmlConvert.ToString(value); JsonValueUtils.WriteQuoted(writer, textValue); } break; case ODataJsonDateTimeFormat.ODataDateTime: { // Uses the same format as DateTime but with offset: // jsonDateTime= quotation-mark // "\/Date(" // ticks // [("+" / "-") offset] // ")\/" // quotation-mark // // ticks = *DIGIT // offset = 4DIGIT string textValue = String.Format( CultureInfo.InvariantCulture, JsonConstants.ODataDateTimeOffsetFormat, JsonValueUtils.DateTimeTicksToJsonTicks(value.Ticks), offsetMinutes >= 0 ? JsonConstants.ODataDateTimeOffsetPlusSign : string.Empty, offsetMinutes); JsonValueUtils.WriteQuoted(writer, textValue); } break; } }
internal static void WriteValue(TextWriter writer, DateTimeOffset value, ODataJsonDateTimeFormat dateTimeFormat) { Debug.Assert(writer != null, "writer != null"); switch (dateTimeFormat) { case ODataJsonDateTimeFormat.ISO8601DateTime: { // Uses the same format as DateTime but with offset: // jsonDateTime= quotation-mark // YYYY-MM-DDThh:mm:ss.sTZD // [("+" / "-") offset] // quotation-mark // // offset = 4DIGIT string textValue = XmlConvert.ToString(value); JsonValueUtils.WriteQuoted(writer, textValue); } break; case ODataJsonDateTimeFormat.ODataDateTime: { // Uses the same format as DateTime but with offset: // jsonDateTime= quotation-mark // "\/Date(" // ticks // [("+" / "-") offset] // ")\/" // quotation-mark // // ticks = *DIGIT // offset = 4DIGIT string textValue = FormatDateTimeAsJsonTicksString(value); JsonValueUtils.WriteQuoted(writer, textValue); } break; } }
/// <summary> /// Write a double value. /// </summary> /// <param name="writer">The text writer to write the output to.</param> /// <param name="value">Double value to be written.</param> internal static void WriteValue(TextWriter writer, double value) { Debug.Assert(writer != null, "writer != null"); if (JsonSharedUtils.IsDoubleValueSerializedAsString(value)) { JsonValueUtils.WriteQuoted(writer, value.ToString(JsonValueUtils.ODataNumberFormatInfo)); } else { // double.ToString() supports a max scale of 14, // whereas double.MinValue and double.MaxValue have 16 digits scale. Hence we need // to use XmlConvert in all other cases, except infinity string valueToWrite = XmlConvert.ToString(value); writer.Write(valueToWrite); if (valueToWrite.IndexOfAny(JsonValueUtils.DoubleIndicatingCharacters) < 0) { writer.Write(".0"); } } }
/// <summary> /// Write a Date value /// </summary> /// <param name="writer">The text writer to write the output to.</param> /// <param name="value">Date value to be written.</param> internal static void WriteValue(TextWriter writer, Date value) { Debug.Assert(writer != null, "writer != null"); JsonValueUtils.WriteQuoted(writer, value.ToString()); }
/// <summary> /// Write a TimeSpan value. /// </summary> /// <param name="writer">The text writer to write the output to.</param> /// <param name="value">TimeSpan value to be written.</param> internal static void WriteValue(TextWriter writer, TimeSpan value) { Debug.Assert(writer != null, "writer != null"); JsonValueUtils.WriteQuoted(writer, EdmValueWriter.DurationAsXml(value)); }