File tree Expand file tree Collapse file tree 2 files changed +19
-2
lines changed
Expand file tree Collapse file tree 2 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -18,5 +18,22 @@ struct DummyValueTypeB { }
1818
1919 [ TestMethod ]
2020 public void TestToWithConstructedNullableNonPrimitive ( ) => Assert . ThrowsException < InvalidCastException > ( ( ) => Conversion . To < DummyValueTypeA ? > ( new DummyValueTypeB { } ) ) ;
21+
22+
23+
24+ [ TestMethod ]
25+ public void TestConvertToFloatUsingNonInvariantNumberFormat ( )
26+ {
27+ try
28+ {
29+ float inputValue = 1234.56f ;
30+ string jsonEncoded = Common . Internal . Json . Encode ( inputValue ) ;
31+ float convertedValue = ( float ) Conversion . ConvertTo < float > ( jsonEncoded ) ;
32+ Assert . IsTrue ( inputValue == convertedValue ) ;
33+ }
34+ catch ( Exception ex )
35+ { throw ex ; }
36+ }
37+
2138 }
2239}
Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ internal static object ConvertTo<T>(object value)
5454
5555 if ( ReflectionHelpers . IsPrimitive ( typeof ( T ) ) )
5656 {
57- return ( T ) Convert . ChangeType ( value , typeof ( T ) ) ;
57+ return ( T ) Convert . ChangeType ( value , typeof ( T ) , System . Globalization . CultureInfo . InvariantCulture ) ;
5858 }
5959
6060 if ( ReflectionHelpers . IsConstructedGenericType ( typeof ( T ) ) )
@@ -65,7 +65,7 @@ internal static object ConvertTo<T>(object value)
6565 Type innerType = ReflectionHelpers . GetGenericTypeArguments ( typeof ( T ) ) [ 0 ] ;
6666 if ( ReflectionHelpers . IsPrimitive ( innerType ) )
6767 {
68- return ( T ) Convert . ChangeType ( value , innerType ) ;
68+ return ( T ) Convert . ChangeType ( value , innerType , System . Globalization . CultureInfo . InvariantCulture ) ;
6969 }
7070 }
7171 Type listType = GetInterfaceType ( value . GetType ( ) , typeof ( IList < > ) ) ;
You can’t perform that action at this time.
0 commit comments