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 { }
18
18
19
19
[ TestMethod ]
20
20
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
+
21
38
}
22
39
}
Original file line number Diff line number Diff line change @@ -54,7 +54,7 @@ internal static object ConvertTo<T>(object value)
54
54
55
55
if ( ReflectionHelpers . IsPrimitive ( typeof ( T ) ) )
56
56
{
57
- return ( T ) Convert . ChangeType ( value , typeof ( T ) ) ;
57
+ return ( T ) Convert . ChangeType ( value , typeof ( T ) , System . Globalization . CultureInfo . InvariantCulture ) ;
58
58
}
59
59
60
60
if ( ReflectionHelpers . IsConstructedGenericType ( typeof ( T ) ) )
@@ -65,7 +65,7 @@ internal static object ConvertTo<T>(object value)
65
65
Type innerType = ReflectionHelpers . GetGenericTypeArguments ( typeof ( T ) ) [ 0 ] ;
66
66
if ( ReflectionHelpers . IsPrimitive ( innerType ) )
67
67
{
68
- return ( T ) Convert . ChangeType ( value , innerType ) ;
68
+ return ( T ) Convert . ChangeType ( value , innerType , System . Globalization . CultureInfo . InvariantCulture ) ;
69
69
}
70
70
}
71
71
Type listType = GetInterfaceType ( value . GetType ( ) , typeof ( IList < > ) ) ;
You can’t perform that action at this time.
0 commit comments