Is it possible to circumvent the following restriction:
Create a static readonly array in a class:
public class A
{
public static readonly int[] Months = new int[] { 1, 2, 3};
}
Then pass it as a parameter to an attribute:
public class FooAttribute : Attribute
{
public int[] Nums { get; set; }
FooAttribute()
{
}
}
--- Let's say Box is a property of class A ---
[Foo(Nums = A.Months)]
public string Box { get; set; }
I know this won't compile and will result in this error:
"An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type".
Is it possible to go around this somehow to be able to use the static array ? I'm asking since this will be much more convenient maintenance-wise, since I have a lot of properties.
Thanks in advance.