@@ -146,6 +146,20 @@ private static bool TryGetParamsConstructorAsDefault(
146146 typeof ( object ) . GetMethod ( nameof ( GetType ) )
147147 ?? throw new InvalidOperationException ( $ "{ nameof ( GetType ) } not found.") ;
148148
149+ [ NotNull ]
150+ private static readonly MethodInfo TypeEqualsMethod =
151+ typeof ( Type ) . GetMethod (
152+ "op_Equality" ,
153+ BindingFlags . Static | BindingFlags . Public ,
154+ null ,
155+ new [ ] { typeof ( Type ) , typeof ( Type ) } ,
156+ null ) ?? throw new InvalidOperationException ( "Cannot find == operator method on Type." ) ;
157+
158+ [ NotNull ]
159+ private static readonly MethodInfo GetTypeFromHandleMethod =
160+ typeof ( Type ) . GetMethod ( nameof ( Type . GetTypeFromHandle ) )
161+ ?? throw new InvalidOperationException ( $ "{ nameof ( Type . GetTypeFromHandle ) } not found.") ;
162+
149163 [ Pure ]
150164 [ NotNull ]
151165 [ ContractAnnotation ( "type:null => halt" ) ]
@@ -205,7 +219,8 @@ void CheckParameterIsOfRightType()
205219 generator . Emit ( OpCodes . Ldarg_0 ) ;
206220 CallMethod ( generator , GetTypeMethod ) ;
207221 generator . Emit ( OpCodes . Ldtoken , type ) ;
208- generator . Emit ( OpCodes . Ceq ) ;
222+ CallMethod ( generator , GetTypeFromHandleMethod ) ;
223+ CallMethod ( generator , TypeEqualsMethod ) ;
209224 generator . Emit ( OpCodes . Brtrue_S , paramIsValid ) ;
210225
211226 // Throw Argument exception => wrong parameter type
0 commit comments