case JsonType.Number:
string s = _value is float || _value is double ?
- ((IFormattable)_value).ToString("R", NumberFormatInfo.InvariantInfo) : // Use "round-trip" format
- ((IFormattable)_value).ToString("G", NumberFormatInfo.InvariantInfo);
+ ((IFormattable)_value).ToString("R", CultureInfo.InvariantCulture) : // Use "round-trip" format
+ ((IFormattable)_value).ToString("G", CultureInfo.InvariantCulture);
return s == "NaN" || s == "Infinity" || s == "-Infinity" ?
"\"" + s + "\"" :
s;
throw new ArgumentNullException(nameof(value));
}
- return Convert.ToBoolean(((JsonPrimitive)value).Value, NumberFormatInfo.InvariantInfo);
+ return Convert.ToBoolean(((JsonPrimitive)value).Value, CultureInfo.InvariantCulture);
}
public static implicit operator byte (JsonValue value)
throw new ArgumentNullException(nameof(value));
}
- return Convert.ToByte(((JsonPrimitive)value).Value, NumberFormatInfo.InvariantInfo);
+ return Convert.ToByte(((JsonPrimitive)value).Value, CultureInfo.InvariantCulture);
}
public static implicit operator char (JsonValue value)
throw new ArgumentNullException(nameof(value));
}
- return Convert.ToChar(((JsonPrimitive)value).Value, NumberFormatInfo.InvariantInfo);
+ return Convert.ToChar(((JsonPrimitive)value).Value, CultureInfo.InvariantCulture);
}
public static implicit operator decimal (JsonValue value)
throw new ArgumentNullException(nameof(value));
}
- return Convert.ToDecimal(((JsonPrimitive)value).Value, NumberFormatInfo.InvariantInfo);
+ return Convert.ToDecimal(((JsonPrimitive)value).Value, CultureInfo.InvariantCulture);
}
public static implicit operator double (JsonValue value)
{
if (value == null)
throw new ArgumentNullException(nameof(value));
- return Convert.ToDouble(((JsonPrimitive)value).Value, NumberFormatInfo.InvariantInfo);
+ return Convert.ToDouble(((JsonPrimitive)value).Value, CultureInfo.InvariantCulture);
}
public static implicit operator float (JsonValue value)
throw new ArgumentNullException(nameof(value));
}
- return Convert.ToSingle(((JsonPrimitive)value).Value, NumberFormatInfo.InvariantInfo);
+ return Convert.ToSingle(((JsonPrimitive)value).Value, CultureInfo.InvariantCulture);
}
public static implicit operator int (JsonValue value)
throw new ArgumentNullException(nameof(value));
}
- return Convert.ToInt32(((JsonPrimitive)value).Value, NumberFormatInfo.InvariantInfo);
+ return Convert.ToInt32(((JsonPrimitive)value).Value, CultureInfo.InvariantCulture);
}
public static implicit operator long (JsonValue value)
throw new ArgumentNullException(nameof(value));
}
- return Convert.ToInt64(((JsonPrimitive)value).Value, NumberFormatInfo.InvariantInfo);
+ return Convert.ToInt64(((JsonPrimitive)value).Value, CultureInfo.InvariantCulture);
}
[CLSCompliant(false)]
throw new ArgumentNullException(nameof(value));
}
- return Convert.ToSByte(((JsonPrimitive)value).Value, NumberFormatInfo.InvariantInfo);
+ return Convert.ToSByte(((JsonPrimitive)value).Value, CultureInfo.InvariantCulture);
}
public static implicit operator short (JsonValue value)
throw new ArgumentNullException(nameof(value));
}
- return Convert.ToInt16(((JsonPrimitive)value).Value, NumberFormatInfo.InvariantInfo);
+ return Convert.ToInt16(((JsonPrimitive)value).Value, CultureInfo.InvariantCulture);
}
public static implicit operator string (JsonValue value)
throw new ArgumentNullException(nameof(value));
}
- return Convert.ToUInt32(((JsonPrimitive)value).Value, NumberFormatInfo.InvariantInfo);
+ return Convert.ToUInt32(((JsonPrimitive)value).Value, CultureInfo.InvariantCulture);
}
[CLSCompliant(false)]
throw new ArgumentNullException(nameof(value));
}
- return Convert.ToUInt64(((JsonPrimitive)value).Value, NumberFormatInfo.InvariantInfo);
+ return Convert.ToUInt64(((JsonPrimitive)value).Value, CultureInfo.InvariantCulture);
}
[CLSCompliant(false)]
throw new ArgumentNullException(nameof(value));
}
- return Convert.ToUInt16(((JsonPrimitive)value).Value, NumberFormatInfo.InvariantInfo);
+ return Convert.ToUInt16(((JsonPrimitive)value).Value, CultureInfo.InvariantCulture);
}
public static implicit operator DateTime(JsonValue value)
// Licensed to the .NET Foundation under one or more agreements.
// See the LICENSE file in the project root for more information.
+using System.Globalization;
using System.IO;
using System.Text;
using Xunit;
[Fact]
public void ToString_DateTimeOffset()
{
- ToString(new JsonPrimitive(DateTimeOffset.MinValue), DateTimeOffset.MinValue.ToString("G"));
+ ToString(new JsonPrimitive(DateTimeOffset.MinValue), DateTimeOffset.MinValue.ToString("G", CultureInfo.InvariantCulture));
}
[Fact]
public void ToString_TimeSpan()
{
- ToString(new JsonPrimitive(TimeSpan.Zero), TimeSpan.Zero.ToString("G"));
+ ToString(new JsonPrimitive(TimeSpan.Zero), TimeSpan.Zero.ToString("G", CultureInfo.InvariantCulture));
}
private void ToString(JsonValue primitive, string expected)
// Licensed to the .NET Foundation under one or more agreements.
// See the LICENSE file in the project root for more information.
+using System.Diagnostics;
using System.IO;
using System.Text;
using System.Globalization;
namespace System.Json.Tests
{
- public class JsonValueTests
+ public class JsonValueTests : RemoteExecutorTestBase
{
[Fact]
public void JsonValue_Load_LoadWithTrailingCommaInDictionary()
[InlineData("0.000000000000000000000000000011", 1.1E-29)]
public void JsonValue_Parse_Double(string json, double expected)
{
- foreach (string culture in new[] { "en", "fr", "de" })
+ RemoteInvoke((jsonInner, expectedInner) =>
{
- CultureInfo old = CultureInfo.CurrentCulture;
- try
+ foreach (string culture in new[] { "en", "fr", "de" })
{
CultureInfo.CurrentCulture = new CultureInfo(culture);
- Assert.Equal(expected, (double)JsonValue.Parse(json));
+ Assert.Equal(double.Parse(expectedInner, CultureInfo.InvariantCulture), (double)JsonValue.Parse(jsonInner));
}
- finally
- {
- CultureInfo.CurrentCulture = old;
- }
- }
+ }, json, expected.ToString("R", CultureInfo.InvariantCulture)).Dispose();
}
// Convert a number to json and parse the string, then compare the result to the original value
[InlineData(1.123456789e-28)] // Values around the smallest positive decimal value
public void JsonValue_Parse_Double_ViaJsonPrimitive(double number)
{
- foreach (string culture in new[] { "en", "fr", "de" })
+ RemoteInvoke(numberText =>
{
- CultureInfo old = CultureInfo.CurrentCulture;
- try
+ double numberInner = double.Parse(numberText, CultureInfo.InvariantCulture);
+ foreach (string culture in new[] { "en", "fr", "de" })
{
CultureInfo.CurrentCulture = new CultureInfo(culture);
- Assert.Equal(number, (double)JsonValue.Parse(new JsonPrimitive(number).ToString()));
+ Assert.Equal(numberInner, (double)JsonValue.Parse(new JsonPrimitive(numberInner).ToString()));
}
- finally
- {
- CultureInfo.CurrentCulture = old;
- }
- }
+ }, number.ToString("R", CultureInfo.InvariantCulture)).Dispose();
}
[Fact]
<Compile Include="JsonObjectTests.cs" />
<Compile Include="JsonPrimitiveTests.cs" />
<Compile Include="JsonValueTests.cs" />
+ <ProjectReference Include="$(CommonTestPath)\System\Diagnostics\RemoteExecutorConsoleApp\RemoteExecutorConsoleApp.csproj">
+ <Project>{69e46a6f-9966-45a5-8945-2559fe337827}</Project>
+ <Name>RemoteExecutorConsoleApp</Name>
+ </ProjectReference>
</ItemGroup>
</Project>
\ No newline at end of file