Interfaces attributes should not be 'proxied' when targeting a transparent proxy (SPRNET-1424)

This commit is contained in:
bbaia
2011-03-29 10:59:08 +00:00
parent 1f3fdfecb9
commit 46831373b5
3 changed files with 36 additions and 6 deletions

View File

@@ -362,7 +362,8 @@ namespace Spring.Proxy
{
ArrayList attributes = new ArrayList();
if (this.ProxyTargetAttributes)
if (this.ProxyTargetAttributes &&
!type.Equals(typeof(object)))
{
// add attributes that apply to the target type
attributes.AddRange(ReflectionUtils.GetCustomAttributes(type));
@@ -388,7 +389,8 @@ namespace Spring.Proxy
{
ArrayList attributes = new ArrayList();
if (this.ProxyTargetAttributes)
if (this.ProxyTargetAttributes &&
!method.DeclaringType.IsInterface)
{
// add attributes that apply to the target method
attributes.AddRange(ReflectionUtils.GetCustomAttributes(method));
@@ -427,7 +429,8 @@ namespace Spring.Proxy
{
ArrayList attributes = new ArrayList();
if (this.ProxyTargetAttributes)
if (this.ProxyTargetAttributes &&
!method.DeclaringType.IsInterface)
{
// add attributes that apply to the target method' return type
object[] attrs = method.ReturnTypeCustomAttributes.GetCustomAttributes(false);
@@ -476,7 +479,8 @@ namespace Spring.Proxy
{
ArrayList attributes = new ArrayList();
if (this.ProxyTargetAttributes)
if (this.ProxyTargetAttributes &&
!method.DeclaringType.IsInterface)
{
// add attributes that apply to the target method's parameter
#if NET_2_0

View File

@@ -707,8 +707,10 @@ namespace Spring.Proxy
{
}
[Marker]
public interface IAnotherMarkerInterface
{
[Marker]
void MarkerMethod();
}

View File

@@ -21,6 +21,8 @@
#region Imports
using System;
using System.Reflection;
using NUnit.Framework;
#endregion
@@ -31,6 +33,7 @@ namespace Spring.Proxy
/// Unit tests for the CompositionProxyTypeBuilder class.
/// </summary>
/// <author>Rick Evans</author>
/// <author>Bruno Baia</author>
[TestFixture]
public class CompositionProxyTypeBuilderTests : AbstractProxyTypeBuilderTests
{
@@ -128,9 +131,30 @@ namespace Spring.Proxy
((IFrameworkInterface)foo).FrameworkMethod();
}
[Test] // SPRNET-1424
public void DoesNotProxyInterfaceMethodAttributes()
{
IProxyTypeBuilder builder = GetProxyBuilder();
builder.TargetType = typeof(object);
builder.Interfaces = new Type[] { typeof(IAnotherMarkerInterface) };
Type proxy = builder.BuildProxyType();
Assert.IsNotNull(proxy, "The proxy generated by a (valid) call to BuildProxy() was null.");
MethodInfo method = proxy.GetMethod("Spring.Proxy.IAnotherMarkerInterface.MarkerMethod", BindingFlags.NonPublic | BindingFlags.Instance);
if (method == null)
{
method = proxy.GetMethod("MarkerMethod");
}
Assert.IsNotNull(method);
object[] attrs = method.GetCustomAttributes(false);
Assert.IsNotNull(attrs, "Should have 0 attribute applied to the target method.");
Assert.AreEqual(0, attrs.Length, "Should have 0 attribute applied to the target method.");
}
protected override IProxyTypeBuilder GetProxyBuilder()
{
return new CompositionProxyTypeBuilder();
}
}
}
}
}