C# - 这可能吗? - [DescriptionAttribute()] 带有文本框文本
枚举中的 DescriptionAttribute
可以包含 TextBox
的文本吗?我问这个问题是因为我有一个包含大量 TextBox
的文件,我希望将它们的内容与我拥有的值相匹配。我怀疑我能做到这一点,但我一点也不确定。
IE
[DescriptionAttribute(textBox1.Text)]
a,
Can a DescriptionAttribute
in an enumeration contain a TextBox
'es text? I ask because I have a file with numerous TextBox
es and I was hoping to match the content of them with a value that I have. I doubt I can do this, but I'm not sure at all.
i.e.
[DescriptionAttribute(textBox1.Text)]
a,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不,属性需要编译时常量作为参数。
C# 规范说:
No, attributes need compile time constants as parameters.
The C# specification says:
不,这是不可能的,因为属性是程序集元数据的一部分,即嵌入在您正在编译的 .dll/.exe 中。
您不能在编译时引用仅在运行时存在的值。
如果您想要类似这样的东西,您必须自己构建它,即创建一个类,在运行时将枚举的字段映射到文本框的值。
No that is no possible, since attributes are part of the assmebly's meta data, i.e. embedded in the .dll/.exe you're compiling.
You cannot, at compile time, refer to a value that will only exist at runtime.
If you want something even remotely like this, you'll have to build it for yourself, i.e., create a class that maps fields of an Enum to the values of textboxes at runtime.
不可以。属性是在编译时定义的,并且必须是常量值。
No. Attributes are defined at compile time and have to be constant values.