@@ -103,9 +103,7 @@ protected override MethodEmitter BuildProxiedMethodBody(MethodEmitter emitter, C
103103
104104 var argumentsMarshaller = new ArgumentsMarshaller ( emitter , MethodToOverride . GetParameters ( ) ) ;
105105
106- argumentsMarshaller . CopyIn ( out var argumentsArray ) ;
107-
108- var hasByRefArguments = HasByRefArguments ( emitter . Arguments ) ;
106+ argumentsMarshaller . CopyIn ( out var argumentsArray , out var hasByRefArguments ) ;
109107
110108 var ctorArguments = GetCtorArguments ( @class , proxiedMethodTokenExpression , argumentsArray , methodInterceptors ) ;
111109 ctorArguments = ModifyArguments ( @class , ctorArguments ) ;
@@ -220,19 +218,6 @@ private IExpression[] ModifyArguments(ClassEmitter @class, IExpression[] argumen
220218 return contributor . GetConstructorInvocationArguments ( arguments , @class ) ;
221219 }
222220
223- private bool HasByRefArguments ( ArgumentReference [ ] arguments )
224- {
225- for ( int i = 0 ; i < arguments . Length ; i ++ )
226- {
227- if ( arguments [ i ] . Type . IsByRef )
228- {
229- return true ;
230- }
231- }
232-
233- return false ;
234- }
235-
236221 private struct ArgumentsMarshaller
237222 {
238223 private readonly MethodEmitter method ;
@@ -244,11 +229,12 @@ public ArgumentsMarshaller(MethodEmitter method, ParameterInfo[] parameters)
244229 this . parameters = parameters ;
245230 }
246231
247- public void CopyIn ( out LocalReference argumentsArray )
232+ public void CopyIn ( out LocalReference argumentsArray , out bool hasByRefArguments )
248233 {
249234 var arguments = method . Arguments ;
250235
251236 argumentsArray = method . CodeBuilder . DeclareLocal ( typeof ( object [ ] ) ) ;
237+ hasByRefArguments = false ;
252238
253239 method . CodeBuilder . AddStatement (
254240 new AssignStatement (
@@ -258,7 +244,16 @@ public void CopyIn(out LocalReference argumentsArray)
258244 for ( int i = 0 , n = arguments . Length ; i < n ; ++ i )
259245 {
260246 var argument = arguments [ i ] ;
261- Reference dereferencedArgument = argument . Type . IsByRef ? new IndirectReference ( argument ) : argument ;
247+ Reference dereferencedArgument ;
248+ if ( argument . Type . IsByRef )
249+ {
250+ dereferencedArgument = new IndirectReference ( argument ) ;
251+ hasByRefArguments = true ;
252+ }
253+ else
254+ {
255+ dereferencedArgument = argument ;
256+ }
262257 var dereferencedArgumentType = dereferencedArgument . Type ;
263258
264259#if FEATURE_BYREFLIKE
0 commit comments