属性不能在C ++ / CLI中重复,但在C#中确定? [英] Attribute cannot be repeated in C++/CLI but OK in C#?

查看:141
本文介绍了属性不能在C ++ / CLI中重复,但在C#中确定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到错误C3095:'Xunit :: Extensions :: InlineDataAttribute':属性不能重复在C ++ / CLI代码但不是C#。

I'm getting error C3095: 'Xunit::Extensions::InlineDataAttribute': attribute cannot be repeated in C++/CLI code but not C#.

xUnit.net 看起来像我的祷告的答案 - 现代单元测试框架,GUI使用C ++ / CLI。然而,使用他们的方法参数化测试给我的错误C3095如下所示。

xUnit.net looks like the answer to my prayers - a modern unit test framework with GUI working with C++/CLI. However, using their approach to parameterised testing gives me the error C3095 as shown below.

有什么想法吗?

我使用最新的xUnit.net 1.6与Visual Studio 2008SP1。

I'm using the latest xUnit.net 1.6 with Visual Studio 2008SP1.

using namespace Xunit;
using namespace Xunit::Extensions;

public ref class ParameterisedTestClass
{
public:

    [Theory]
    [InlineData("Kilroy", 6)]
    // uncomment to cause c3095 [InlineData("Jones", 5)]
    void PropTest(String^ msg, int msgLen)
    {
        Assert::Equal(msg->Length, msgLen);
    }
};

C#中的等效项是正确的

the equivalent in C# is fine

using Xunit;
using Xunit.Extensions;

public  class ParameterisedTestClass
{

    [Theory]
    [InlineData("Kilroy", 6)]
    [InlineData("Jones", 5)]
    public void PropTest(String msg, int msgLen)
    {
        Assert.Equal(msg.Length, msgLen);
    }
};


推荐答案

嗯...我看着defs 此处此处,并将其复制(减少);在C#中继承 AllowMultiple 通过 DataAttribute 可以正常工作:

Hmmm... I looked at the defs here and here, and reproduced them (cut-down) below; the inheritance of AllowMultiple via DataAttribute works fine in C#:

class Test
{
    [InlineData]
    [InlineData]
    static void Main() { }
}

[AttributeUsage(AttributeTargets.Method, AllowMultiple = true, Inherited = true)]
class DataAttribute : Attribute {}

class InlineDataAttribute : DataAttribute { }

所以如果它不工作在C ++ / CLI,我猜C ++ / CLI根本不是处理隐含的 [AttributeUsage] 。您应该针对Xunit提出请求,要求他们使 [AttributeUsage] InlineDataAttribute 上显式。

So if it isn't working for C++/CLI, I guess C++/CLI simply isn't processing the implied [AttributeUsage]. You should file a request against Xunit asking them to make the [AttributeUsage] explicit on InlineDataAttribute.

这篇关于属性不能在C ++ / CLI中重复,但在C#中确定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆