@@ -4149,30 +4149,30 @@ protected static object ChangeType(object value, Type conversionType)
4149
4149
return Enum . ToObject ( conversionType , value ) ;
4150
4150
}
4151
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
- }
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
+ // }
4176
4176
4177
4177
if ( DynamicCast ( value , conversionType , out object ret ) )
4178
4178
{
@@ -4188,19 +4188,23 @@ protected static bool DynamicCast(object source, Type destType, out object resul
4188
4188
if ( srcType == destType ) { result = source ; return true ; }
4189
4189
result = null ;
4190
4190
4191
- BindingFlags bf = BindingFlags . Static | BindingFlags . Public ;
4192
- MethodInfo castOperator = destType . GetMethods ( bf )
4193
- . Union ( srcType . GetMethods ( bf ) )
4194
- . Where ( mi => mi . Name == "op_Explicit" || mi . Name == "op_Implicit" )
4195
- . Where ( mi =>
4191
+ BindingFlags bindingFlags = BindingFlags . Static | BindingFlags . Public | BindingFlags . FlattenHierarchy ;
4192
+ MethodInfo castOperator = destType . GetMethods ( bindingFlags )
4193
+ . Union ( srcType . GetMethods ( bindingFlags ) )
4194
+ . Where ( methodInfo => methodInfo . Name == "op_Explicit" || methodInfo . Name == "op_Implicit" )
4195
+ . Where ( methodInfo =>
4196
4196
{
4197
- var pars = mi . GetParameters ( ) ;
4197
+ var pars = methodInfo . GetParameters ( ) ;
4198
4198
return pars . Length == 1 && pars [ 0 ] . ParameterType == srcType ;
4199
4199
} )
4200
4200
. Where ( mi => mi . ReturnType == destType )
4201
4201
. FirstOrDefault ( ) ;
4202
- if ( castOperator != null ) result = castOperator . Invoke ( null , new object [ ] { source } ) ;
4203
- else return false ;
4202
+
4203
+ if ( castOperator != null )
4204
+ result = castOperator . Invoke ( null , new object [ ] { source } ) ;
4205
+ else
4206
+ return false ;
4207
+
4204
4208
return true ;
4205
4209
}
4206
4210
0 commit comments