I'm trying to implement a generic class. It should have a property with an attribute that takes a compile-time constant, which I want to set as the parameter type's name. Something like this:
namespace Example
{
public class MyGeneric<T>
{
[SomeAttribute(CompileTimeConstant)]
public int MyProperty { get; set; }
private const string CompileTimeConstant = typeof(T).Name; // error CS0133:
// The expression being assigned to `Example.MyGeneric<T>.CompileTimeConstant' must be constant
}
}
But because typeof(T).Name
is evaluated at run-time, it doesn't work. Is it possible?