Skip to content

Commit 4c6293a

Browse files
committed
Reduce usage of NHibernate.Proxy.DynamicProxy.IProxy
1 parent b6f16b6 commit 4c6293a

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

src/NHibernate/Proxy/DynamicProxy/DefaultMethodEmitter.cs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,12 @@
1010
using System.Diagnostics;
1111
using System.Reflection;
1212
using System.Reflection.Emit;
13-
using NHibernate.Linq;
1413
using NHibernate.Util;
1514

1615
namespace NHibernate.Proxy.DynamicProxy
1716
{
1817
internal class DefaultMethodEmitter : IMethodBodyEmitter
1918
{
20-
private static readonly MethodInfo getInterceptor;
21-
2219
private static readonly MethodInfo handlerMethod = ReflectHelper.GetMethod<IInterceptor>(
2320
i => i.Intercept(null));
2421
private static readonly MethodInfo getArguments = typeof(InvocationInfo).GetMethod("get_Arguments");
@@ -33,15 +30,12 @@ internal class DefaultMethodEmitter : IMethodBodyEmitter
3330
typeof (object[])
3431
});
3532

36-
private static readonly PropertyInfo interceptorProperty = typeof (IProxy).GetProperty("Interceptor");
37-
3833
private static readonly ConstructorInfo notImplementedConstructor = typeof(NotImplementedException).GetConstructor(new System.Type[0]);
3934

4035
private readonly IArgumentHandler _argumentHandler;
4136

4237
static DefaultMethodEmitter()
4338
{
44-
getInterceptor = interceptorProperty.GetGetMethod();
4539
}
4640

4741
public DefaultMethodEmitter() : this(new DefaultArgumentHandler()) {}
@@ -60,12 +54,12 @@ public void EmitMethodBody(MethodBuilder proxyMethod, MethodBuilder callbackMeth
6054
ParameterInfo[] parameters = method.GetParameters();
6155
IL.DeclareLocal(typeof (object[]));
6256
IL.DeclareLocal(typeof (InvocationInfo));
63-
IL.DeclareLocal(typeof(System.Type[]));
57+
IL.DeclareLocal(typeof (System.Type[]));
6458

6559
IL.Emit(OpCodes.Ldarg_0);
66-
IL.Emit(OpCodes.Callvirt, getInterceptor);
60+
IL.Emit(OpCodes.Ldfld, field);
6761

68-
// if (interceptor == null)
62+
// if (this.interceptor == null)
6963
// return base.method(...);
7064

7165
Label skipBaseCall = IL.DefineLabel();
@@ -90,9 +84,9 @@ public void EmitMethodBody(MethodBuilder proxyMethod, MethodBuilder callbackMeth
9084
IL.Emit(OpCodes.Newobj, infoConstructor);
9185
IL.Emit(OpCodes.Stloc_1);
9286

93-
// this.Interceptor.Intercept(info);
87+
// this.interceptor.Intercept(info);
9488
IL.Emit(OpCodes.Ldarg_0);
95-
IL.Emit(OpCodes.Callvirt, getInterceptor);
89+
IL.Emit(OpCodes.Ldfld, field);
9690
IL.Emit(OpCodes.Ldloc_1);
9791
IL.Emit(OpCodes.Callvirt, handlerMethod);
9892

src/NHibernate/Proxy/DynamicProxy/ProxyObjectReference.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@ namespace NHibernate.Proxy.DynamicProxy
1616
[Serializable]
1717
public class ProxyObjectReference : IObjectReference, ISerializable
1818
{
19-
private readonly System.Type _baseType;
20-
private readonly IProxy _proxy;
19+
private readonly object _proxy;
2120

2221
protected ProxyObjectReference(SerializationInfo info, StreamingContext context)
2322
{
2423
// Deserialize the base type using its assembly qualified name
2524
string qualifiedName = info.GetString("__baseType");
26-
_baseType = System.Type.GetType(qualifiedName, true, false);
25+
var baseType = System.Type.GetType(qualifiedName, true, false);
2726

2827
// Rebuild the list of interfaces
2928
var interfaceList = new List<System.Type>();
@@ -39,11 +38,11 @@ protected ProxyObjectReference(SerializationInfo info, StreamingContext context)
3938

4039
// Reconstruct the proxy
4140
var factory = new ProxyFactory();
42-
System.Type proxyType = factory.CreateProxyType(_baseType, interfaceList.ToArray());
41+
System.Type proxyType = factory.CreateProxyType(baseType, interfaceList.ToArray());
4342

4443
// Initialize the proxy with the deserialized data
4544
var args = new object[] {info, context};
46-
_proxy = (IProxy) Activator.CreateInstance(proxyType, args);
45+
_proxy = Activator.CreateInstance(proxyType, args);
4746
}
4847

4948
#region IObjectReference Members

0 commit comments

Comments
 (0)