Using variables within Attributes in C#

后端 未结 2 1093
面向向阳花
面向向阳花 2020-12-09 15:32

We have some Well-Attributed DB code, like so:

[Display(Name = \"Phone Number\")]
public string Phone { get; set; }

Since it is quite gen

2条回答
  •  既然无缘
    2020-12-09 16:12

    Everything inside an attribute must be known to the compiler at compile-time. Variables are inherently variable (!) so can't be used in attributes.

    If you can use a code generation tool, you'd be able to dynamically inject different (constant) values into each derived class.

提交回复
热议问题