diff --git a/src/Spring/Spring.Core/Proxy/AbstractProxyTypeBuilder.cs b/src/Spring/Spring.Core/Proxy/AbstractProxyTypeBuilder.cs index 7db27e02..78d97f2e 100644 --- a/src/Spring/Spring.Core/Proxy/AbstractProxyTypeBuilder.cs +++ b/src/Spring/Spring.Core/Proxy/AbstractProxyTypeBuilder.cs @@ -291,9 +291,9 @@ namespace Spring.Proxy /// protected virtual void ApplyMethodReturnTypeAttributes(MethodBuilder methodBuilder, MethodInfo targetMethod) { + ParameterBuilder parameterBuilder = methodBuilder.DefineParameter(0, ParameterAttributes.Retval, null); foreach (object attr in GetMethodReturnTypeAttributes(targetMethod)) { - ParameterBuilder parameterBuilder = methodBuilder.DefineParameter(0, ParameterAttributes.Retval, null); if (attr is CustomAttributeBuilder) { parameterBuilder.SetCustomAttribute((CustomAttributeBuilder)attr); @@ -322,10 +322,10 @@ namespace Spring.Proxy { foreach (ParameterInfo paramInfo in targetMethod.GetParameters()) { + ParameterBuilder parameterBuilder = methodBuilder.DefineParameter( + (paramInfo.Position + 1), paramInfo.Attributes, paramInfo.Name); foreach (object attr in GetMethodParameterAttributes(targetMethod, paramInfo)) { - ParameterBuilder parameterBuilder = methodBuilder.DefineParameter( - (paramInfo.Position + 1), paramInfo.Attributes, paramInfo.Name); if (attr is CustomAttributeBuilder) { parameterBuilder.SetCustomAttribute((CustomAttributeBuilder)attr); diff --git a/test/Spring/Spring.Core.Tests/Proxy/AbstractProxyTypeBuilderTests.cs b/test/Spring/Spring.Core.Tests/Proxy/AbstractProxyTypeBuilderTests.cs index d8454920..5cfd25e8 100644 --- a/test/Spring/Spring.Core.Tests/Proxy/AbstractProxyTypeBuilderTests.cs +++ b/test/Spring/Spring.Core.Tests/Proxy/AbstractProxyTypeBuilderTests.cs @@ -410,6 +410,27 @@ namespace Spring.Proxy Assert.AreEqual(typeof(MarkerAttribute), attrs[0].GetType(), "Wrong System.Type of Attribute applied to the method's parameter."); } + [Test] + [Description("SPRNET-1134")] + public void ProxyTargetMethodParameterMultipleAttributes() + { + IProxyTypeBuilder builder = GetProxyBuilder(); + builder.TargetType = typeof(MultipleMarkerClass); + Type proxy = builder.BuildProxyType(); + Assert.IsNotNull(proxy, "The proxy generated by a (valid) call to BuildProxy() was null."); + MethodInfo method = proxy.GetMethod("Spring.Proxy.ISomeMarkerInterface.MarkerMethod", BindingFlags.NonPublic | BindingFlags.Instance); + if (method == null) + { + method = proxy.GetMethod("MarkerMethod"); + } + Assert.IsNotNull(method); + object[] attrs = method.GetParameters()[1].GetCustomAttributes(false); + Assert.IsNotNull(attrs, "Should have had 2 attributes applied to the method's parameter."); + Assert.AreEqual(2, attrs.Length, "Should have had 2 attributes applied to the method's parameter."); + Assert.AreEqual(typeof(MarkerAttribute), attrs[0].GetType(), "Wrong System.Type of Attribute applied to the method's parameter."); + Assert.AreEqual(typeof(MarkerAttribute), attrs[1].GetType(), "Wrong System.Type of Attribute applied to the method's parameter."); + } + [Test] public void DoesNotProxyTargetMethodParameterAttributesWithProxyTargetAttributesEqualsFalse() { @@ -449,6 +470,27 @@ namespace Spring.Proxy Assert.AreEqual(typeof(MarkerAttribute), attrs[0].GetType(), "Wrong System.Type of Attribute applied to the method's return value."); } + [Test] + [Description("SPRNET-1134")] + public void ProxyTargetMethodReturnValueMultipleAttributes() + { + IProxyTypeBuilder builder = GetProxyBuilder(); + builder.TargetType = typeof(MultipleMarkerClass); + Type proxy = builder.BuildProxyType(); + Assert.IsNotNull(proxy, "The proxy generated by a (valid) call to BuildProxy() was null."); + MethodInfo method = proxy.GetMethod("Spring.Proxy.ISomeMarkerInterface.MarkerMethod", BindingFlags.NonPublic | BindingFlags.Instance); + if (method == null) + { + method = proxy.GetMethod("MarkerMethod"); + } + Assert.IsNotNull(method); + object[] attrs = method.ReturnTypeCustomAttributes.GetCustomAttributes(false); + Assert.IsNotNull(attrs, "Should have had 2 attribute applied to the method's return value."); + Assert.AreEqual(2, attrs.Length, "Should have had 2 attribute applied to the method's return value."); + Assert.AreEqual(typeof(MarkerAttribute), attrs[0].GetType(), "Wrong System.Type of Attribute applied to the method's return value."); + Assert.AreEqual(typeof(MarkerAttribute), attrs[1].GetType(), "Wrong System.Type of Attribute applied to the method's return value."); + } + [Test] public void DoesNotProxyTargetMethodReturnValueAttributesWithProxyTargetAttributesEqualsFalse() { @@ -780,6 +822,24 @@ namespace Spring.Proxy } } + // SPRNET-1134 + public class MultipleMarkerClass : ISomeMarkerInterface + { + [return: Marker(Count=0)] + [return: Marker(Count=1)] + public string MarkerMethod(int param1, [Marker(Count = 0)][Marker(Count = 1)]string param2) + { + return string.Empty; + } + + [return: Marker(Count = 0)] + [return: Marker(Count = 1)] + public virtual string MarkerVirtualMethod(int param1, [Marker(Count = 0)][Marker(Count = 1)]string param2) + { + return string.Empty; + } + } + [Marker] public class AnotherMarkerClass : IAnotherMarkerInterface { @@ -842,6 +902,7 @@ namespace Spring.Proxy } } + [AttributeUsage(AttributeTargets.All, AllowMultiple=true)] public sealed class MarkerAttribute : Attribute { private int _count; diff --git a/test/Spring/Spring.Core.Tests/Proxy/InheritanceProxyTypeBuilderTests.cs b/test/Spring/Spring.Core.Tests/Proxy/InheritanceProxyTypeBuilderTests.cs index 8247d77b..ea7ae07b 100644 --- a/test/Spring/Spring.Core.Tests/Proxy/InheritanceProxyTypeBuilderTests.cs +++ b/test/Spring/Spring.Core.Tests/Proxy/InheritanceProxyTypeBuilderTests.cs @@ -242,6 +242,23 @@ namespace Spring.Proxy Assert.AreEqual(typeof(MarkerAttribute), attrs[0].GetType(), "Wrong System.Type of Attribute applied to the method's parameter."); } + [Test] + [Description("SPRNET-1134")] + public void ProxyTargetVirtualMethodParameterMultipleAttributes() + { + IProxyTypeBuilder builder = GetProxyBuilder(); + builder.TargetType = typeof(MultipleMarkerClass); + Type proxy = builder.BuildProxyType(); + Assert.IsNotNull(proxy, "The proxy generated by a (valid) call to BuildProxy() was null."); + MethodInfo method = proxy.GetMethod("MarkerVirtualMethod"); + Assert.IsNotNull(method); + object[] attrs = method.GetParameters()[1].GetCustomAttributes(false); + Assert.IsNotNull(attrs, "Should have had 2 attribute applied to the method's parameter."); + Assert.AreEqual(2, attrs.Length, "Should have had 2 attribute applied to the method's parameter."); + Assert.AreEqual(typeof(MarkerAttribute), attrs[0].GetType(), "Wrong System.Type of Attribute applied to the method's parameter."); + Assert.AreEqual(typeof(MarkerAttribute), attrs[1].GetType(), "Wrong System.Type of Attribute applied to the method's parameter."); + } + [Test] public void DoesNotProxyTargetVirtualMethodParameterAttributesWithProxyTargetAttributesEqualsFalse() { @@ -273,6 +290,23 @@ namespace Spring.Proxy Assert.AreEqual(typeof(MarkerAttribute), attrs[0].GetType(), "Wrong System.Type of Attribute applied to the method's return value."); } + [Test] + [Description("SPRNET-1134")] + public void ProxyTargetVirtualMethodReturnValueMultipleAttributes() + { + IProxyTypeBuilder builder = GetProxyBuilder(); + builder.TargetType = typeof(MultipleMarkerClass); + Type proxy = builder.BuildProxyType(); + Assert.IsNotNull(proxy, "The proxy generated by a (valid) call to BuildProxy() was null."); + MethodInfo method = proxy.GetMethod("MarkerVirtualMethod"); + Assert.IsNotNull(method); + object[] attrs = method.ReturnTypeCustomAttributes.GetCustomAttributes(false); + Assert.IsNotNull(attrs, "Should have had 2 attribute applied to the method's return value."); + Assert.AreEqual(2, attrs.Length, "Should have had 2 attribute applied to the method's return value."); + Assert.AreEqual(typeof(MarkerAttribute), attrs[0].GetType(), "Wrong System.Type of Attribute applied to the method's return value."); + Assert.AreEqual(typeof(MarkerAttribute), attrs[1].GetType(), "Wrong System.Type of Attribute applied to the method's return value."); + } + [Test] public void DoesNotProxyTargetVirtualMethodReturnValueAttributesWithProxyTargetAttributesEqualsFalse() {