在属性构造函数中使用变量

Use a variable in an attribute constructor

是否可以在属性构造函数中使用变量,如下所示:

[Foo(bar)]
public string Baz { get; set; }

问题有效,但其中包含对不相关上下文的引用。真的应该这样写:


是否可以在属性构造函数中使用变量,如下所示:

[Foo(bar)]
public string Baz { get; set; }

正如 Stephen Muecke 所说,答案是否定的。

attributes add metadata and are evaluated a compile-time so therefore must be constants