Spring.Proxy classes does not generate correctly multiple parameters attributes (method's parameter attributes and method's return type attributes [SPRNET-1134]

This commit is contained in:
bbaia
2008-12-09 23:07:51 +00:00
parent 182e3997ba
commit 7b5d53d376
3 changed files with 98 additions and 3 deletions

View File

@@ -291,9 +291,9 @@ namespace Spring.Proxy
/// <see cref="IProxyTypeBuilder.ProxyTargetAttributes"/>
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);

View File

@@ -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;

View File

@@ -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()
{