ジェネリッククラスを実装しようとしています。パラメータ型の名前として設定したいコンパイル時の定数を取る属性を持つプロパティが必要です。このようなもの:
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
}
}
ただしtypeof(T).Name
、実行時に評価されるため、機能しません。出来ますか?