@@ -4148,31 +4148,13 @@ protected static object ChangeType(object value, Type conversionType)
4148
4148
{
4149
4149
return Enum . ToObject ( conversionType , value ) ;
4150
4150
}
4151
-
4152
- //if(conversionType == typeof(int))
4153
- //{
4154
- // return (int)(dynamic)value;
4155
- //}
4156
- //if (conversionType == typeof(uint))
4157
- //{
4158
- // return (uint)(dynamic)value;
4159
- //}
4160
- //if (conversionType == typeof(long))
4161
- //{
4162
- // return (long)(dynamic)value;
4163
- //}
4164
- //if (conversionType == typeof(ulong))
4165
- //{
4166
- // return (ulong)(dynamic)value;
4167
- //}
4168
- //if (conversionType == typeof(short))
4169
- //{
4170
- // return (short)(dynamic)value;
4171
- //}
4172
- //if (conversionType == typeof(ushort))
4173
- //{
4174
- // return (ushort)(dynamic)value;
4175
- //}
4151
+
4152
+ if ( value . GetType ( ) . IsPrimitive && conversionType . IsPrimitive )
4153
+ {
4154
+ return primitiveExplicitCastMethodInfo
4155
+ . MakeGenericMethod ( conversionType )
4156
+ . Invoke ( null , new object [ ] { value } ) ;
4157
+ }
4176
4158
4177
4159
if ( DynamicCast ( value , conversionType , out object ret ) )
4178
4160
{
@@ -4182,6 +4164,13 @@ protected static object ChangeType(object value, Type conversionType)
4182
4164
return Convert . ChangeType ( value , conversionType ) ;
4183
4165
}
4184
4166
4167
+ protected static MethodInfo primitiveExplicitCastMethodInfo = typeof ( ExpressionEvaluator ) . GetMethod ( nameof ( PrimitiveExplicitCast ) , BindingFlags . Static | BindingFlags . NonPublic ) ;
4168
+
4169
+ protected static object PrimitiveExplicitCast < T > ( dynamic value )
4170
+ {
4171
+ return ( T ) value ;
4172
+ }
4173
+
4185
4174
protected static bool DynamicCast ( object source , Type destType , out object result )
4186
4175
{
4187
4176
Type srcType = source . GetType ( ) ;
0 commit comments