我有以下属性定义:属性与动态对象
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
class TestAttribute : Attribute
{
public TestAttribute(List<string> values)
{
}
}
以下使用的属性产生一个错误:
[Test(new List<string>() { "123", "456" }]
class A
{
}
错误是:
An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type.
不限请帮助?我正在使用Visual Studio 2012 .NET 4.5。我不想使用params string[]
而不是List<string>
。
尝试一个数组,然后呢? – Ryan
对不起,我只是编辑了问题家伙,你现在可以看看它。 – hiddenUser
是的 - 现在它是有道理的! –