User: xtoff
Date: 2010/02/20 12:08 PM
Modified:
/DynamicProxy/trunk/src/Castle.DynamicProxy.Tests/
ExplicitInterfaceTestCase.cs
/DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/
ClassMembersCollector.cs, ClassProxyTargetContributor.cs,
CompositeTypeContributor.cs, InterfaceMembersCollector.cs,
InterfaceMembersOnClassCollector.cs
/DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/
MetaMethod.cs
Log:
- some minor changes to set the stage for intercepting explicitly implemented
interface members on classes
File Changes:
Directory: /DynamicProxy/trunk/src/Castle.DynamicProxy.Tests/
=============================================================
File [modified]: ExplicitInterfaceTestCase.cs
Delta lines: +0 -0
===================================================================
Directory: /DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/
====================================================================
File [modified]: ClassMembersCollector.cs
Delta lines: +34 -13
===================================================================
---
DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/ClassProxyTargetContributor.cs
2010-02-20 18:53:44 UTC (rev 6751)
+++
DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/ClassProxyTargetContributor.cs
2010-02-20 19:08:29 UTC (rev 6752)
@@ -1,4 +1,4 @@
-// Copyright 2004-2009 Castle Project - http://www.castleproject.org/
+// Copyright 2004-2010 Castle Project - http://www.castleproject.org/
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
@@ -26,10 +26,11 @@
public class ClassProxyTargetContributor : CompositeTypeContributor
{
+ private readonly IList<MethodInfo> methodsToSkip;
private readonly Type targetType;
- private readonly IList<MethodInfo> methodsToSkip;
- public ClassProxyTargetContributor(Type targetType,
IList<MethodInfo> methodsToSkip, INamingScope namingScope):base(namingScope)
+ public ClassProxyTargetContributor(Type targetType,
IList<MethodInfo> methodsToSkip, INamingScope namingScope)
+ : base(namingScope)
{
this.targetType = targetType;
this.methodsToSkip = methodsToSkip;
@@ -53,9 +54,14 @@
}
}
- protected override MethodGenerator
GetMethodGenerator(MetaMethod method, ClassEmitter @class,
ProxyGenerationOptions options, CreateMethodDelegate createMethod)
+ protected override MethodGenerator
GetMethodGenerator(MetaMethod method, ClassEmitter @class,
+
ProxyGenerationOptions options,
+
CreateMethodDelegate createMethod)
{
- if (methodsToSkip.Contains(method.Method)) return null;
+ if (methodsToSkip.Contains(method.Method))
+ {
+ return null;
+ }
if (!method.Proxyable)
{
@@ -72,16 +78,10 @@
createMethod);
}
- private Type GetInvocationType(MetaMethod method, ClassEmitter
@class, ProxyGenerationOptions options)
- {
- // NOTE: No caching since invocation is tied to this
specific proxy type via its invocation method
- return BuildInvocationType(method, @class, options);
- }
-
private Type BuildInvocationType(MetaMethod method,
ClassEmitter @class, ProxyGenerationOptions options)
{
var methodInfo = method.Method;
- if (!method.HasTarget)
+ if (method.MethodOnTarget.IsAbstract)
{
return new
ClassInvocationTypeGenerator(targetType,
method,
@@ -89,6 +89,15 @@
.Generate(@class, options, namingScope)
.BuildType();
}
+ if (ExplicitlyImplementedInterfaceMethod(method))
+ {
+ // TODO: enable intercepting these
+ return new
ClassInvocationTypeGenerator(targetType,
+ method,
+ null)
+ .Generate(@class, options, namingScope)
+ .BuildType();
+ }
var callback = CreateCallbackMethod(@class, methodInfo,
method.MethodOnTarget);
return new
ClassInvocationTypeGenerator(callback.DeclaringType,
method,
@@ -126,9 +135,21 @@
// invocation on base class
callBackMethod.CodeBuilder.AddStatement(
- new ReturnStatement(new
MethodInvocationExpression(SelfReference.Self, targetMethod, exps)));
+ new
ReturnStatement(new MethodInvocationExpression(SelfReference.Self,
+
targetMethod, exps)));
return callBackMethod.MethodBuilder;
}
+
+ private bool ExplicitlyImplementedInterfaceMethod(MetaMethod
method)
+ {
+ return method.MethodOnTarget.IsPrivate;
+ }
+
+ private Type GetInvocationType(MetaMethod method, ClassEmitter
@class, ProxyGenerationOptions options)
+ {
+ // NOTE: No caching since invocation is tied to this
specific proxy type via its invocation method
+ return BuildInvocationType(method, @class, options);
+ }
}
}
File [modified]: ClassProxyTargetContributor.cs
Delta lines: +9 -9
===================================================================
---
DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/CompositeTypeContributor.cs
2010-02-20 18:53:44 UTC (rev 6751)
+++
DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/CompositeTypeContributor.cs
2010-02-20 19:08:29 UTC (rev 6752)
@@ -99,7 +99,6 @@
Debug.Assert(@interface.IsInterface,
"@interface.IsInterface", "Should be adding interfaces only...");
Debug.Assert(!interfaces.Contains(@interface),
"!interfaces.ContainsKey(@interface)", "Shouldn't be adding same interface
twice...");
-
interfaces.Add(@interface);
}
@@ -132,17 +131,18 @@
ProxyGenerationOptions options, CreateMethodDelegate createMethod);
private void ImplementMethod(MetaMethod method, ClassEmitter
@class, ProxyGenerationOptions options,
- CreateMethodDelegate
createMethod)
+
CreateMethodDelegate createMethod)
{
+
+ var generator = GetMethodGenerator(method, @class,
options, createMethod);
+ if (generator == null) return;
+
+ var proxyMethod = generator.Generate(@class, options,
namingScope);
+ foreach (var attribute in
AttributeUtil.GetNonInheritableAttributes(method.Method))
{
- var generator = GetMethodGenerator(method,
@class, options, createMethod);
- if (generator == null) return;
- var proxyMethod = generator.Generate(@class,
options, namingScope);
- foreach (var attribute in
AttributeUtil.GetNonInheritableAttributes(method.Method))
- {
-
proxyMethod.DefineCustomAttribute(attribute);
- }
+ proxyMethod.DefineCustomAttribute(attribute);
}
+
}
}
}
File [modified]: CompositeTypeContributor.cs
Delta lines: +1 -1
===================================================================
---
DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/InterfaceMembersCollector.cs
2010-02-20 18:53:44 UTC (rev 6751)
+++
DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/InterfaceMembersCollector.cs
2010-02-20 19:08:29 UTC (rev 6752)
@@ -34,7 +34,7 @@
}
var proxyable = AcceptMethod(method, false, hook);
- return new MetaMethod(method, method, isStandalone,
proxyable, false);
+ return new MetaMethod(method, method, isStandalone,
proxyable);
}
File [modified]: InterfaceMembersCollector.cs
Delta lines: +1 -1
===================================================================
---
DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/InterfaceMembersOnClassCollector.cs
2010-02-20 18:53:44 UTC (rev 6751)
+++
DynamicProxy/trunk/src/Castle.DynamicProxy/Contributors/InterfaceMembersOnClassCollector.cs
2010-02-20 19:08:29 UTC (rev 6752)
@@ -30,7 +30,7 @@
var methodOnTarget = GetMethodOnTarget(method);
var proxyable = AcceptMethod(method, onlyProxyVirtual,
hook);
- return new MetaMethod(method, methodOnTarget,
isStandalone, proxyable, methodOnTarget.IsPrivate == false);
+ return new MetaMethod(method, methodOnTarget,
isStandalone, proxyable);
}
File [modified]: InterfaceMembersOnClassCollector.cs
Delta lines: +1 -4
===================================================================
--- DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/MetaMethod.cs
2010-02-20 18:53:44 UTC (rev 6751)
+++ DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/MetaMethod.cs
2010-02-20 19:08:29 UTC (rev 6752)
@@ -29,7 +29,7 @@
MethodAttributes.NewSlot |
MethodAttributes.Final;
- public MetaMethod(MethodInfo method, MethodInfo methodOnTarget,
bool standalone, bool proxyable, bool hasTarget)
+ public MetaMethod(MethodInfo method, MethodInfo methodOnTarget,
bool standalone, bool proxyable)
: base(method.DeclaringType)
{
Method = method;
@@ -37,7 +37,6 @@
MethodOnTarget = methodOnTarget;
Standalone = standalone;
Proxyable = proxyable;
- HasTarget = hasTarget;
Attributes = ObtainAttributes();
}
@@ -93,8 +92,6 @@
public MethodInfo Method { get; private set; }
- public bool HasTarget { get; private set; }
-
public bool Equals(MetaMethod other)
{
Directory: /DynamicProxy/trunk/src/Castle.DynamicProxy/Generators/
==================================================================
File [modified]: MetaMethod.cs
Delta lines: +1 -1
===================================================================
---
DynamicProxy/trunk/src/Castle.DynamicProxy.Tests/ExplicitInterfaceTestCase.cs
2010-02-20 18:53:44 UTC (rev 6751)
+++
DynamicProxy/trunk/src/Castle.DynamicProxy.Tests/ExplicitInterfaceTestCase.cs
2010-02-20 19:08:29 UTC (rev 6752)
@@ -21,7 +21,7 @@
using NUnit.Framework;
- [TestFixture]
+ [TestFixture("TODO: Enable proxying explicit implementations:
DYNPROXY-ISSUE-107")]
public class ExplicitInterfaceTestCase : BasePEVerifyTestCase
{
--
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=en.