@@ -45,8 +45,13 @@ static ValueConverter()
45
45
Register ( typeof ( long ) , typeof ( int ) , LongToInt ) ;
46
46
Register ( typeof ( long ) , typeof ( uint ) , LongToUInt ) ;
47
47
Register ( typeof ( long ) , typeof ( ulong ) , LongToULong ) ;
48
+ Register ( typeof ( long ) , typeof ( double ) , LongToDouble ) ;
49
+ Register ( typeof ( long ) , typeof ( decimal ) , LongToDecimal ) ;
48
50
Register ( typeof ( long ) , typeof ( TimeSpan ) , LongToTimeSpan ) ;
49
51
52
+ Register ( typeof ( float ) , typeof ( double ) , FloatToDouble ) ;
53
+ Register ( typeof ( float ) , typeof ( decimal ) , FloatToDecimal ) ;
54
+
50
55
Register ( typeof ( double ) , typeof ( decimal ) , DoubleToDecimal ) ;
51
56
52
57
Register ( typeof ( string ) , typeof ( Uri ) , ParseUri ) ;
@@ -64,12 +69,36 @@ private static object IntToDecimal(object value)
64
69
return Convert . ToDecimal ( intValue , NumberFormatInfo . InvariantInfo ) ;
65
70
}
66
71
72
+ private static object FloatToDouble ( object value )
73
+ {
74
+ var floatValue = ( float ) value ;
75
+ return ( double ) floatValue ;
76
+ }
77
+
78
+ private static object FloatToDecimal ( object value )
79
+ {
80
+ var floatValue = ( float ) value ;
81
+ return Convert . ToDecimal ( floatValue , NumberFormatInfo . InvariantInfo ) ;
82
+ }
83
+
67
84
private static object DoubleToDecimal ( object value )
68
85
{
69
86
var doubleValue = ( double ) value ;
70
87
return Convert . ToDecimal ( doubleValue , NumberFormatInfo . InvariantInfo ) ;
71
88
}
72
89
90
+ private static object LongToDouble ( object value )
91
+ {
92
+ var longValue = ( long ) value ;
93
+ return ( double ) longValue ;
94
+ }
95
+
96
+ private static object LongToDecimal ( object value )
97
+ {
98
+ var longValue = ( long ) value ;
99
+ return ( decimal ) longValue ;
100
+ }
101
+
73
102
private static object LongToInt ( object value )
74
103
{
75
104
var longValue = ( long ) value ;
@@ -210,8 +239,6 @@ private static object convertToUInt32<T>(T value) =>
210
239
private static object convertToUInt64 < T > ( T value ) =>
211
240
Convert . ToUInt64 ( value , NumberFormatInfo . InvariantInfo ) ;
212
241
213
-
214
-
215
242
public static object ConvertTo ( object value , Type targetType )
216
243
{
217
244
if ( value == null )
0 commit comments