Closed stakx closed 1 year ago
If #639 gets merged, we can half the number of test cases here, because the distinction between nested / non-nested attribute types will no longer be relevant.
If we additionally eliminate the distinction between inheritable / non-inheritable attributes (since DynamicProxy generally won't replicate the former), we can reduce the tests for this issue to just this:
namespace Castle.DynamicProxy.Tests;
using System;
using NUnit.Framework;
[TestFixture]
public class Tests : BasePEVerifyTestCase
{
[TestCase(typeof(I3))]
[TestCase(typeof(I4))]
public void Can_proxy_type(Type interfaceTypeToProxy)
{
_ = generator.CreateInterfaceProxyWithoutTarget(interfaceTypeToProxy);
}
[NonInheritedAttributeWithOnePositionalArrayParameter(null)]
public interface I3 { }
[NonInheritedAttributeWithOnePositionalArrayParameter(new object[0])]
public interface I4 { }
[AttributeUsage(AttributeTargets.Interface, Inherited = false)]
public sealed class NonInheritedAttributeWithOnePositionalArrayParameterAttribute : Attribute
{
public NonInheritedAttributeWithOnePositionalArrayParameterAttribute(object[] arg) { }
}
}
@kimbirkelund made a bug report over at the Moq 4 repository that boils down to a problem with how DynamicProxy processes array parameters of custom attributes. Given the following test code:
The test case using
I7
fails with:That is, the error surfaces only when the following conditions are met:
null
is used as the argument value.I haven't studied this in more detail yet, but it seems something goes wrong in the "special case for handling arrays in attributes" logic here.