User: xtoff
Date: 2009/11/15 05:24 AM
Modified:
/DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/
InterfaceProxyTargetContributor.cs,
InterfaceProxyWithoutTargetContributor.cs, MixinContributor.cs
/DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/
InterfaceInvocationTypeGenerator.cs, InterfaceMethodGenerator.cs,
InvocationTypeGenerator.cs, MethodWithCallbackGenerator.cs
/DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/Emitters/
ClassEmitter.cs
Log:
- extracted invocation types for non-class-methods out of proxy types, as
first step towards implementing DYNPROXY-ISSUE-105. Now non-class-methods are
kept in Castle.Invocations namespace and named with format
InterfaceName_MethodName_Suffix.
Class-methods invocations are still kept as nested types as they call callback
method on proxy types, so they're tied to single proxy type anyway, and there's
no point in extracting them out.
File Changes:
Directory: /DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/
====================================================================
File [modified]: InterfaceProxyTargetContributor.cs
Delta lines: +1 -1
===================================================================
---
DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/InterfaceProxyWithoutTargetContributor.cs
2009-11-15 11:19:24 UTC (rev 6330)
+++
DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/InterfaceProxyWithoutTargetContributor.cs
2009-11-15 12:24:41 UTC (rev 6331)
@@ -107,7 +107,7 @@
method,
method.MethodOnTarget,
false)
- .Generate(@class, options, namingScope);
+ .Generate(@class, options,
namingScope).BuildType();
generator = new InterfaceMethodGenerator(method,
File [modified]: InterfaceProxyWithoutTargetContributor.cs
Delta lines: +2 -2
===================================================================
--- DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/MixinContributor.cs
2009-11-15 11:19:24 UTC (rev 6330)
+++ DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/MixinContributor.cs
2009-11-15 12:24:41 UTC (rev 6331)
@@ -116,11 +116,11 @@
MethodGenerator generator;
if (method.Proxyable)
{
- var invocation = new
InvocationTypeGenerator(method.Method.DeclaringType,
+ var invocation = new
InterfaceInvocationTypeGenerator(method.Method.DeclaringType,
method,
method.Method,
canChangeTarget)
- .Generate(emitter, options,
namingScope);
+ .Generate(emitter, options,
namingScope).BuildType();
var interceptors =
emitter.GetField("__interceptors");
File [modified]: MixinContributor.cs
Delta lines: +7 -0
===================================================================
---
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/Emitters/ClassEmitter.cs
2009-11-15 11:19:24 UTC (rev 6330)
+++
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/Emitters/ClassEmitter.cs
2009-11-15 12:24:41 UTC (rev 6331)
@@ -21,6 +21,7 @@
public class ClassEmitter : AbstractTypeEmitter
{
+ private ModuleScope moduleScope;
private const TypeAttributes DefaultAttributes =
TypeAttributes.Public | TypeAttributes.Class | TypeAttributes.Serializable;
public ClassEmitter(ModuleScope modulescope, String name, Type
baseType, IEnumerable<Type> interfaces)
@@ -43,8 +44,14 @@
}
TypeBuilder.SetParent(baseType);
+ moduleScope = modulescope;
}
+ public ModuleScope ModuleScope
+ {
+ get { return moduleScope; }
+ }
+
private static TypeBuilder CreateTypeBuilder(ModuleScope
modulescope, string name, Type baseType, IEnumerable<Type> interfaces,
TypeAttributes
flags, bool forceUnsigned)
Directory: /DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/Emitters/
===========================================================================
File [modified]: ClassEmitter.cs
Delta lines: +10 -1
===================================================================
---
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/InterfaceInvocationTypeGenerator.cs
2009-11-15 11:19:24 UTC (rev 6330)
+++
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/InterfaceInvocationTypeGenerator.cs
2009-11-15 12:24:41 UTC (rev 6331)
@@ -27,8 +27,17 @@
{
}
- protected override void
ImplementInvokeMethodOnTarget(NestedClassEmitter nested, ParameterInfo[]
parameters, MethodEmitter method, MethodInfo callbackMethod, Reference
targetField)
+ protected override AbstractTypeEmitter GetEmitter(ClassEmitter
@class, Type[] interfaces, INamingScope namingScope, MethodInfo methodInfo)
{
+ return new ClassEmitter(@class.ModuleScope,
+ namingScope.GetUniqueName(
+
string.Format("Castle.Invocations.{0}_{1}", methodInfo.DeclaringType.Name,
methodInfo.Name)),
+ typeof(AbstractInvocation),
interfaces);
+
+ }
+
+ protected override void
ImplementInvokeMethodOnTarget(AbstractTypeEmitter nested, ParameterInfo[]
parameters, MethodEmitter method, MethodInfo callbackMethod, Reference
targetField)
+ {
method.CodeBuilder.AddStatement(
new ExpressionStatement(
Directory: /DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/
==================================================================
File [modified]: InterfaceInvocationTypeGenerator.cs
Delta lines: +4 -5
===================================================================
---
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/InterfaceMethodGenerator.cs
2009-11-15 11:19:24 UTC (rev 6330)
+++
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/InterfaceMethodGenerator.cs
2009-11-15 12:24:41 UTC (rev 6331)
@@ -29,11 +29,11 @@
public class InterfaceMethodGenerator : InterfaceMethodGeneratorBase
{
- private readonly NestedClassEmitter invocation;
+ private readonly Type invocation;
private readonly FieldReference interceptors;
private readonly GetTargetExpressionDelegate
getTargetExpression;
- public InterfaceMethodGenerator(MethodToGenerate method,
NestedClassEmitter invocation, FieldReference interceptors,
CreateMethodDelegate createMethod,GetTargetExpressionDelegate
getTargetExpression)
+ public InterfaceMethodGenerator(MethodToGenerate method, Type
invocation, FieldReference interceptors, CreateMethodDelegate
createMethod,GetTargetExpressionDelegate getTargetExpression)
:base(method,createMethod)
{
Debug.Assert(method.MethodOnTarget != null,
"method.MethodOnTarget != null");
@@ -47,14 +47,14 @@
var methodInfo = Method.Method;
emitter.CopyParametersAndReturnTypeFrom(methodInfo,
@class);
- Type invocationType = invocation.TypeBuilder;
+ Type invocationType = invocation;
//TODO: can this ever happen? Should we throw instead?
Trace.Assert(methodInfo.IsGenericMethod ==
invocationType.IsGenericTypeDefinition);
Expression interfaceMethod;
- ConstructorInfo constructor =
invocation.Constructors[0].ConstructorBuilder;
+ ConstructorInfo constructor =
invocationType.GetConstructors()[0];
Type[] genericMethodArgs = Type.EmptyTypes;
@@ -63,7 +63,6 @@
// bind generic method arguments to
invocation's type arguments
genericMethodArgs =
emitter.MethodBuilder.GetGenericArguments();
invocationType =
invocationType.MakeGenericType(genericMethodArgs);
-
constructor =
TypeBuilder.GetConstructor(invocationType, constructor);
File [modified]: InterfaceMethodGenerator.cs
Delta lines: +26 -22
===================================================================
---
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/InvocationTypeGenerator.cs
2009-11-15 11:19:24 UTC (rev 6330)
+++
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/InvocationTypeGenerator.cs
2009-11-15 12:24:41 UTC (rev 6331)
@@ -22,7 +22,7 @@
using Emitters.SimpleAST;
using Tokens;
- public class InvocationTypeGenerator : IGenerator<NestedClassEmitter>
+ public class InvocationTypeGenerator : IGenerator<AbstractTypeEmitter>
{
private readonly Type targetType;
private readonly IProxyMethod method;
@@ -37,7 +37,7 @@
this.canChangeTarget = canChangeTarget;
}
- public NestedClassEmitter Generate(ClassEmitter @class,
ProxyGenerationOptions options, INamingScope namingScope)
+ public AbstractTypeEmitter Generate(ClassEmitter @class,
ProxyGenerationOptions options, INamingScope namingScope)
{
var methodInfo = method.Method;
@@ -47,57 +47,61 @@
{
interfaces = new[] { typeof(IChangeProxyTarget)
};
}
- var nested =
- new NestedClassEmitter(@class,
- "Invocation_" +
namingScope.GetUniqueName(methodInfo.Name),
- typeof
(AbstractInvocation),
- interfaces);
+ var type = GetEmitter(@class,
interfaces,namingScope,methodInfo);
// invocation only needs to mirror the generic
parameters of the MethodInfo
// targetType cannot be a generic type definition
- nested.CopyGenericParametersFromMethod(methodInfo);
+ type.CopyGenericParametersFromMethod(methodInfo);
// Create constructor
- CreateIInvocationConstructor(targetType,
nested,options);
+ CreateIInvocationConstructor(targetType, type,options);
var targetField = new
FieldReference(InvocationMethods.Target);
if (canChangeTarget)
{
- ImplementChangeProxyTargetInterface(@class,
nested, targetField);
+ ImplementChangeProxyTargetInterface(@class,
type, targetField);
}
// InvokeMethodOnTarget implementation
if (callback != null)
{
- CreateIInvocationInvokeOnTarget(nested,
methodInfo.GetParameters(), targetField, callback);
+ CreateIInvocationInvokeOnTarget(type,
methodInfo.GetParameters(), targetField, callback);
}
else if (method.HasTarget)
{
- CreateIInvocationInvokeOnTarget(nested,
methodInfo.GetParameters(), targetField, methodInfo);
+ CreateIInvocationInvokeOnTarget(type,
methodInfo.GetParameters(), targetField, methodInfo);
}
else
{
- CreateEmptyIInvocationInvokeOnTarget(nested);
+ CreateEmptyIInvocationInvokeOnTarget(type);
}
#if !SILVERLIGHT
- nested.DefineCustomAttribute<SerializableAttribute>();
+ type.DefineCustomAttribute<SerializableAttribute>();
#endif
- return nested;
+ return type;
}
- private void ImplementChangeProxyTargetInterface(ClassEmitter
@class, NestedClassEmitter invocation, FieldReference targetField)
+ protected virtual AbstractTypeEmitter GetEmitter(ClassEmitter
@class, Type[] interfaces, INamingScope namingScope, MethodInfo methodInfo)
{
+ return new NestedClassEmitter(@class,
+
namingScope.GetUniqueName("Invocation_" + methodInfo.Name),
+
typeof(AbstractInvocation),
+ interfaces);
+ }
+
+ private void ImplementChangeProxyTargetInterface(ClassEmitter
@class, AbstractTypeEmitter invocation, FieldReference targetField)
+ {
ImplementChangeInvocationTarget(invocation,
targetField);
ImplementChangeProxyTarget(invocation, @class);
}
- private void ImplementChangeProxyTarget(NestedClassEmitter
invocation, ClassEmitter @class)
+ private void ImplementChangeProxyTarget(AbstractTypeEmitter
invocation, ClassEmitter @class)
{
var argument = new ArgumentReference(typeof(object));
var changeInvocationTarget =
invocation.CreateMethod("ChangeProxyTarget",
@@ -117,7 +121,7 @@
changeInvocationTarget.CodeBuilder.AddStatement(new
ReturnStatement());
}
- private void ImplementChangeInvocationTarget(NestedClassEmitter
invocation, FieldReference targetField)
+ private void
ImplementChangeInvocationTarget(AbstractTypeEmitter invocation, FieldReference
targetField)
{
var argument = new ArgumentReference(typeof (object));
var changeInvocationTarget =
invocation.CreateMethod("ChangeInvocationTarget",
@@ -130,7 +134,7 @@
changeInvocationTarget.CodeBuilder.AddStatement(new
ReturnStatement());
}
- protected void
CreateIInvocationInvokeOnTarget(NestedClassEmitter nested, ParameterInfo[]
parameters, FieldReference targetField, MethodInfo callbackMethod)
+ protected void
CreateIInvocationInvokeOnTarget(AbstractTypeEmitter nested, ParameterInfo[]
parameters, FieldReference targetField, MethodInfo callbackMethod)
{
const MethodAttributes methodAtts =
MethodAttributes.Public | MethodAttributes.Final | MethodAttributes.Virtual;
@@ -139,7 +143,7 @@
ImplementInvokeMethodOnTarget(nested, parameters,
method, callbackMethod, targetField);
}
- protected virtual void
ImplementInvokeMethodOnTarget(NestedClassEmitter nested, ParameterInfo[]
parameters, MethodEmitter method, MethodInfo callbackMethod, Reference
targetField)
+ protected virtual void
ImplementInvokeMethodOnTarget(AbstractTypeEmitter nested, ParameterInfo[]
parameters, MethodEmitter method, MethodInfo callbackMethod, Reference
targetField)
{
if (canChangeTarget)
@@ -236,7 +240,7 @@
- protected void
CreateEmptyIInvocationInvokeOnTarget(NestedClassEmitter nested)
+ protected void
CreateEmptyIInvocationInvokeOnTarget(AbstractTypeEmitter nested)
{
const MethodAttributes methodAtts =
MethodAttributes.Public | MethodAttributes.Final | MethodAttributes.Virtual;
@@ -258,7 +262,7 @@
/// <param name="targetFieldType"></param>
/// <param name="nested"></param>
/// <param name="proxyGenerationOptions"></param>
- protected void CreateIInvocationConstructor(Type
targetFieldType, NestedClassEmitter nested, ProxyGenerationOptions
proxyGenerationOptions)
+ protected void CreateIInvocationConstructor(Type
targetFieldType, AbstractTypeEmitter nested, ProxyGenerationOptions
proxyGenerationOptions)
{
var target = new ArgumentReference(targetFieldType);
File [modified]: InvocationTypeGenerator.cs
Delta lines: +3 -4
===================================================================
---
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/MethodWithCallbackGenerator.cs
2009-11-15 11:19:24 UTC (rev 6330)
+++
DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/MethodWithCallbackGenerator.cs
2009-11-15 12:24:41 UTC (rev 6331)
@@ -29,11 +29,11 @@
public class MethodWithCallbackGenerator:MethodGenerator
{
private readonly MethodToGenerate method;
- private readonly NestedClassEmitter invocation;
+ private readonly AbstractTypeEmitter invocation;
private readonly Reference interceptors;
private readonly CreateMethodDelegate createMethod;
- public MethodWithCallbackGenerator(MethodToGenerate method,
NestedClassEmitter invocation, Reference interceptors, CreateMethodDelegate
createMethod)
+ public MethodWithCallbackGenerator(MethodToGenerate method,
AbstractTypeEmitter invocation, Reference interceptors, CreateMethodDelegate
createMethod)
{
this.method = method;
this.invocation = invocation;
@@ -48,7 +48,6 @@
var methodEmitter = createMethod(name, atts);
var proxiedMethod =
ImplementProxiedMethod(methodEmitter,
@class,
- options,
namingScope);
if (method.Method.DeclaringType.IsInterface)
@@ -59,7 +58,7 @@
return proxiedMethod;
}
- private MethodEmitter ImplementProxiedMethod(MethodEmitter
emitter, ClassEmitter @class, ProxyGenerationOptions options,INamingScope
namingScope)
+ private MethodEmitter ImplementProxiedMethod(MethodEmitter
emitter, ClassEmitter @class,INamingScope namingScope)
{
var methodInfo = method.Method;
File [modified]: MethodWithCallbackGenerator.cs
Delta lines: +0 -0
===================================================================
--
You received this message because you are subscribed to the Google Groups
"Castle Project Commits" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/castle-project-commits?hl=.