|
10 | 10 | using System.Diagnostics;
|
11 | 11 | using System.Reflection;
|
12 | 12 | using System.Reflection.Emit;
|
| 13 | +using NHibernate.Linq; |
| 14 | +using NHibernate.Util; |
13 | 15 |
|
14 | 16 | namespace NHibernate.Proxy.DynamicProxy
|
15 | 17 | {
|
16 | 18 | internal class DefaultMethodEmitter : IMethodBodyEmitter
|
17 | 19 | {
|
18 | 20 | private static readonly MethodInfo getInterceptor;
|
19 | 21 |
|
20 |
| - private static readonly MethodInfo getGenericMethodFromHandle = typeof (MethodBase).GetMethod("GetMethodFromHandle", |
21 |
| - BindingFlags.Public | BindingFlags.Static, null, |
22 |
| - new[] {typeof (RuntimeMethodHandle), typeof (RuntimeTypeHandle)}, null); |
23 |
| - |
24 |
| - private static readonly MethodInfo getMethodFromHandle = typeof (MethodBase).GetMethod("GetMethodFromHandle", new[] {typeof (RuntimeMethodHandle)}); |
25 |
| - private static readonly MethodInfo getTypeFromHandle = typeof(System.Type).GetMethod("GetTypeFromHandle"); |
26 |
| - private static readonly MethodInfo handlerMethod = typeof (IInterceptor).GetMethod("Intercept"); |
| 22 | + private static readonly MethodInfo handlerMethod = ReflectionHelper.GetMethod<IInterceptor>( |
| 23 | + i => i.Intercept(null)); |
| 24 | + private static readonly MethodInfo getArguments = typeof(InvocationInfo).GetMethod("get_Arguments"); |
27 | 25 |
|
28 | 26 | private static readonly ConstructorInfo infoConstructor = typeof (InvocationInfo).GetConstructor(new[]
|
29 | 27 | {
|
@@ -118,7 +116,6 @@ private static void EmitBaseMethodCall(ILGenerator IL, MethodInfo method)
|
118 | 116 | private static void SaveRefArguments(ILGenerator IL, ParameterInfo[] parameters)
|
119 | 117 | {
|
120 | 118 | // Save the arguments returned from the handler method
|
121 |
| - MethodInfo getArguments = typeof (InvocationInfo).GetMethod("get_Arguments"); |
122 | 119 | IL.Emit(OpCodes.Ldloc_1);
|
123 | 120 | IL.Emit(OpCodes.Call, getArguments);
|
124 | 121 | IL.Emit(OpCodes.Stloc_0);
|
@@ -192,11 +189,11 @@ private static void PushTargetMethodInfo(ILGenerator IL, MethodBuilder generated
|
192 | 189 | if (declaringType.IsGenericType)
|
193 | 190 | {
|
194 | 191 | IL.Emit(OpCodes.Ldtoken, declaringType);
|
195 |
| - IL.Emit(OpCodes.Call, getGenericMethodFromHandle); |
| 192 | + IL.Emit(OpCodes.Call, ReflectionCache.MethodBaseMethods.GetMethodFromHandleWithDeclaringType); |
196 | 193 | }
|
197 | 194 | else
|
198 | 195 | {
|
199 |
| - IL.Emit(OpCodes.Call, getMethodFromHandle); |
| 196 | + IL.Emit(OpCodes.Call, ReflectionCache.MethodBaseMethods.GetMethodFromHandle); |
200 | 197 | }
|
201 | 198 |
|
202 | 199 | IL.Emit(OpCodes.Castclass, typeof(MethodInfo));
|
@@ -232,7 +229,7 @@ private void PushGenericArguments(MethodInfo method, ILGenerator IL)
|
232 | 229 | IL.Emit(OpCodes.Dup);
|
233 | 230 | IL.Emit(OpCodes.Ldc_I4, index);
|
234 | 231 | IL.Emit(OpCodes.Ldtoken, currentType);
|
235 |
| - IL.Emit(OpCodes.Call, getTypeFromHandle); |
| 232 | + IL.Emit(OpCodes.Call, ReflectionCache.TypeMethods.GetTypeFromHandle); |
236 | 233 | IL.Emit(OpCodes.Stelem_Ref);
|
237 | 234 | }
|
238 | 235 | }
|
|
0 commit comments