Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
NH-2857: Medium Trust Bug in 3.2 - duplicated the reference to the In…
…terceptor so the generated code is visible in Reflector
  • Loading branch information
FlukeFan committed Jan 24, 2012
1 parent 5b8654f commit e20f9be
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/NHibernate/Proxy/DynamicProxy/DefaultMethodEmitter.cs
Expand Up @@ -66,13 +66,11 @@ public void EmitMethodBody(ILGenerator IL, MethodInfo method, FieldInfo field)
// if (interceptor == null)
// return base.method(...);

Label skipThrow = IL.DefineLabel();
Label skipBaseCall = IL.DefineLabel();

IL.Emit(OpCodes.Dup);
IL.Emit(OpCodes.Ldnull);
IL.Emit(OpCodes.Bne_Un, skipThrow);
IL.Emit(OpCodes.Bne_Un, skipBaseCall);

IL.Emit(OpCodes.Pop); // get rid of the reference to the duplicated interceptor
IL.Emit(OpCodes.Ldarg_0);

for(int i=0; i<method.GetParameters().Length; i++)
Expand All @@ -81,7 +79,8 @@ public void EmitMethodBody(ILGenerator IL, MethodInfo method, FieldInfo field)
IL.Emit(OpCodes.Call, method);
IL.Emit(OpCodes.Ret);

IL.MarkLabel(skipThrow);
IL.MarkLabel(skipBaseCall);

// Push the 'this' pointer onto the stack
IL.Emit(OpCodes.Ldarg_0);

Expand Down Expand Up @@ -109,6 +108,10 @@ public void EmitMethodBody(ILGenerator IL, MethodInfo method, FieldInfo field)

IL.Emit(OpCodes.Newobj, infoConstructor);
IL.Emit(OpCodes.Stloc_1);

// this.Interceptor.Intercept(info);
IL.Emit(OpCodes.Ldarg_0);
IL.Emit(OpCodes.Callvirt, getInterceptor);
IL.Emit(OpCodes.Ldloc_1);
IL.Emit(OpCodes.Callvirt, handlerMethod);

Expand Down

0 comments on commit e20f9be

Please sign in to comment.