Update of /cvsroot/springnet/Spring.Net/src/Spring/Spring.Aop/Aop/Framework/DynamicProxy
In directory sc8-pr-cvs8.sourceforge.net:/tmp/cvs-serv16301/Aop/Framework/DynamicProxy
Modified Files:
AbstractAopProxyMethodBuilder.cs AdvisedProxy.cs
Added Files:
BaseAopProxyMethodBuilder.cs InheritanceAopProxyTypeBuilder.cs
Log Message:
Added Inheritance-based aop proxy.
--- NEW FILE: InheritanceAopProxyTypeBuilder.cs ---
(This appears to be a binary file; contents omitted.)
Index: AdvisedProxy.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Aop/Aop/Framework/DynamicProxy/AdvisedProxy.cs,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -d -r1.9 -r1.10
*** AdvisedProxy.cs 8 Oct 2007 22:04:51 -0000 1.9
--- AdvisedProxy.cs 6 Feb 2008 18:28:52 -0000 1.10
***************
*** 203,211 ****
/// <param name="targetType">target type</param>
/// <param name="targetMethod">taget method to invoke</param>
/// <param name="args">method arguments</param>
/// <param name="interceptors">interceptor chain</param>
/// <returns>value returned by invocation chain</returns>
! public object Invoke(object proxy, object target, Type targetType,
! MethodInfo targetMethod, object[] args, IList interceptors)
{
IMethodInvocation invocation = null;
--- 203,212 ----
/// <param name="targetType">target type</param>
/// <param name="targetMethod">taget method to invoke</param>
+ /// <param name="proxyMethod">The method to invoke on proxy.</param>
/// <param name="args">method arguments</param>
/// <param name="interceptors">interceptor chain</param>
/// <returns>value returned by invocation chain</returns>
! public object Invoke(object proxy, object target, Type targetType,
! MethodInfo targetMethod, MethodInfo proxyMethod, object[] args, IList interceptors)
{
IMethodInvocation invocation = null;
***************
*** 213,222 ****
{
invocation = new DynamicMethodInvocation(
! proxy, target, targetMethod, args, targetType, interceptors);
}
else
{
invocation = new ReflectiveMethodInvocation(
! proxy, target, targetMethod, args, targetType, interceptors);
}
return invocation.Proceed();
--- 214,223 ----
{
invocation = new DynamicMethodInvocation(
! proxy, target, targetMethod, proxyMethod, args, targetType, interceptors);
}
else
{
invocation = new ReflectiveMethodInvocation(
! proxy, target, targetMethod, proxyMethod, args, targetType, interceptors);
}
return invocation.Proceed();
Index: AbstractAopProxyMethodBuilder.cs
===================================================================
RCS file: /cvsroot/springnet/Spring.Net/src/Spring/Spring.Aop/Aop/Framework/DynamicProxy/AbstractAopProxyMethodBuilder.cs,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** AbstractAopProxyMethodBuilder.cs 2 Aug 2007 16:28:29 -0000 1.8
--- AbstractAopProxyMethodBuilder.cs 6 Feb 2008 18:28:52 -0000 1.9
***************
*** 28,31 ****
--- 28,32 ----
using Spring.Proxy;
+ using Spring.Util;
#endregion
***************
*** 54,57 ****
--- 55,64 ----
protected IDictionary targetMethods;
+ /// <summary>
+ /// The dictionary to cache the list of target
+ /// <see cref="System.Reflection.MethodInfo"/>s defined on the proxy.
+ /// </summary>
+ protected IDictionary onProxyTargetMethods;
+
// variables
***************
*** 79,85 ****
/// <summary>
/// The local variable to store the closed generic method
! /// when the proxied method is generic.
/// </summary>
protected LocalBuilder genericTargetMethod;
#endif
/// <summary>
--- 86,98 ----
/// <summary>
/// The local variable to store the closed generic method
! /// when the target method is generic.
/// </summary>
protected LocalBuilder genericTargetMethod;
+
+ /// <summary>
+ /// The local variable to store the closed generic method
+ /// when the target method defined on the proxy is generic.
+ /// </summary>
+ protected LocalBuilder genericOnProxyTargetMethod;
#endif
/// <summary>
***************
*** 87,90 ****
--- 100,109 ----
/// </summary>
protected FieldBuilder targetMethodCacheField;
+
+ /// <summary>
+ /// The field to cache the target <see cref="System.Reflection.MethodInfo"/>
+ /// defined on the proxy.
+ /// </summary>
+ protected FieldBuilder onProxyTargetMethodCacheField;
// convinience fields
***************
*** 136,145 ****
/// </param>
protected AbstractAopProxyMethodBuilder(
! TypeBuilder typeBuilder, IAopProxyTypeGenerator aopProxyGenerator,
bool explicitImplementation, IDictionary targetMethods)
: base(typeBuilder, aopProxyGenerator, explicitImplementation)
{
this.aopProxyGenerator = aopProxyGenerator;
this.targetMethods = targetMethods;
}
--- 155,191 ----
/// </param>
protected AbstractAopProxyMethodBuilder(
! TypeBuilder typeBuilder, IAopProxyTypeGenerator aopProxyGenerator,
bool explicitImplementation, IDictionary targetMethods)
+ : this(typeBuilder, aopProxyGenerator, explicitImplementation, targetMethods, new Hashtable())
+ {
+ }
+
+ /// <summary>
+ /// Creates a new instance of the method builder.
+ /// </summary>
+ /// <param name="typeBuilder">The type builder to use.</param>
+ /// <param name="aopProxyGenerator">
+ /// The <see cref="IAopProxyTypeGenerator"/> implementation to use.
+ /// </param>
+ /// <param name="explicitImplementation">
+ /// <see langword="true"/> if the interface is to be
+ /// implemented explicitly; otherwise <see langword="false"/>.
+ /// </param>
+ /// <param name="targetMethods">
+ /// The dictionary to cache the list of target
+ /// <see cref="System.Reflection.MethodInfo"/>s.
+ /// </param>
+ /// <param name="onProxyTargetMethods">
+ /// The dictionary to cache the list of target
+ /// <see cref="System.Reflection.MethodInfo"/>s defined on the proxy.
+ /// </param>
+ protected AbstractAopProxyMethodBuilder(
+ TypeBuilder typeBuilder, IAopProxyTypeGenerator aopProxyGenerator,
+ bool explicitImplementation, IDictionary targetMethods, IDictionary onProxyTargetMethods)
: base(typeBuilder, aopProxyGenerator, explicitImplementation)
{
this.aopProxyGenerator = aopProxyGenerator;
this.targetMethods = targetMethods;
+ this.onProxyTargetMethods = onProxyTargetMethods;
}
***************
*** 164,167 ****
--- 210,214 ----
GenerateTargetMethodCacheField(il, method);
+ GenerateOnProxyTargetMethodCacheField(il, method);
BeginMethod(il, method);
***************
*** 195,198 ****
--- 242,275 ----
#if NET_2_0
+ MakeGenericMethod(il, method, targetMethodCacheField, genericTargetMethod);
+ #endif
+ }
+
+ /// <summary>
+ /// Create static field that will cache target method when defined on the proxy.
+ /// </summary>
+ /// <param name="il">The IL generator to use.</param>
+ /// <param name="method">The target method.</param>
+ protected virtual void GenerateOnProxyTargetMethodCacheField(
+ ILGenerator il, MethodInfo method)
+ {
+ }
+
+ #if NET_2_0
+ /// <summary>
+ /// Create a closed generic method for the current call
+ /// if target method is a generic definition.
+ /// </summary>
+ /// <param name="il">The IL generator to use.</param>
+ /// <param name="method">The target method.</param>
+ /// <param name="methodCacheField">
+ /// The field that contains the method generic definition
+ /// </param>
+ /// <param name="localMethod">
+ /// The local variable to store the closed generic method.
+ /// </param>
+ protected void MakeGenericMethod(ILGenerator il, MethodInfo method,
+ FieldBuilder methodCacheField, LocalBuilder localMethod)
+ {
// if target method is a generic definition,
// create a closed generic method for the current call.
***************
*** 203,207 ****
LocalBuilder typeArgs = il.DeclareLocal(typeof(Type[]));
! il.Emit(OpCodes.Ldsfld, targetMethodCacheField);
// specify array size and create an array
--- 280,284 ----
LocalBuilder typeArgs = il.DeclareLocal(typeof(Type[]));
! il.Emit(OpCodes.Ldsfld, methodCacheField);
// specify array size and create an array
***************
*** 222,229 ****
il.Emit(OpCodes.Ldloc, typeArgs);
il.Emit(OpCodes.Callvirt, References.MakeGenericMethod);
! il.Emit(OpCodes.Stloc, genericTargetMethod);
}
- #endif
}
/// <summary>
--- 299,306 ----
il.Emit(OpCodes.Ldloc, typeArgs);
il.Emit(OpCodes.Callvirt, References.MakeGenericMethod);
! il.Emit(OpCodes.Stloc, localMethod);
}
}
+ #endif
/// <summary>
***************
*** 267,270 ****
--- 344,371 ----
/// <summary>
+ /// Pushes the target <see cref="System.Reflection.MethodInfo"/> defined on the proxy to stack.
+ /// </summary>
+ /// <param name="il">The IL generator to use.</param>
+ /// <param name="method">The method to proxy.</param>
+ protected virtual void PushOnProxyTargetMethodInfo(ILGenerator il, MethodInfo method)
+ {
+ if (onProxyTargetMethodCacheField != null)
+ {
+ #if NET_2_0
+ if (method.IsGenericMethodDefinition)
+ {
+ il.Emit(OpCodes.Ldloc, genericOnProxyTargetMethod);
+ return;
+ }
+ #endif
+ il.Emit(OpCodes.Ldsfld, onProxyTargetMethodCacheField);
+ }
+ else
+ {
+ il.Emit(OpCodes.Ldnull);
+ }
+ }
+
+ /// <summary>
/// Creates local variable declarations.
/// </summary>
***************
*** 281,284 ****
--- 382,386 ----
{
genericTargetMethod = il.DeclareLocal(typeof(MethodInfo));
+ genericOnProxyTargetMethod = il.DeclareLocal(typeof(MethodInfo));
}
#endif
***************
*** 296,299 ****
--- 398,402 ----
{
genericTargetMethod.SetLocalSymInfo("genericTargetMethod");
+ genericOnProxyTargetMethod.SetLocalSymInfo("genericOnProxyTargetMethod");
}
#endif
***************
*** 400,403 ****
--- 503,507 ----
il.Emit(OpCodes.Ldloc, targetType); // target type
PushTargetMethodInfo(il, method); // method
+ PushOnProxyTargetMethodInfo(il, method); // method defined on proxy
il.Emit(OpCodes.Ldloc, arguments); // args
il.Emit(OpCodes.Ldloc, interceptors); // interceptors
***************
*** 638,642 ****
public static readonly MethodInfo InvokeMethod =
! typeof(AdvisedProxy).GetMethod("Invoke", BindingFlags.Instance | BindingFlags.Public, null, new Type[] { typeof(Object), typeof(Object), typeof(Type), typeof(MethodInfo), typeof(Object[]), typeof(IList) }, null);
public static readonly MethodInfo GetInterceptorsMethod =
--- 742,746 ----
public static readonly MethodInfo InvokeMethod =
! typeof(AdvisedProxy).GetMethod("Invoke", BindingFlags.Instance | BindingFlags.Public, null, new Type[] { typeof(Object), typeof(Object), typeof(Type), typeof(MethodInfo), typeof(MethodInfo), typeof(Object[]), typeof(IList) }, null);
public static readonly MethodInfo GetInterceptorsMethod =
--- NEW FILE: BaseAopProxyMethodBuilder.cs ---
(This appears to be a binary file; contents omitted.)
|