问题描述
我有一个属性,我想将文本从资源文件加载到属性中.
I have an attribute and i want to load text to the attribute from a resource file.
[IntegerValidation(1, 70, ErrorMessage = Data.Messages.Speed)]
private int i_Speed;
但我不断得到"属性参数必须是属性参数类型的常量表达式、typeof表达式或数组创建表达式"
But I keep getting "An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type"
如果我添加一个字符串而不是 Data.Messages.Text,它会完美运行,例如:
It works perfectly if i add a string instead of Data.Messages.Text, like:
[IntegerValidation(1, 70, ErrorMessage = "Invalid max speed")]
有什么想法吗?
推荐答案
编译时属性值被硬编码到程序集中.如果你想在执行时做任何事情,你需要使用一个常量作为key,然后将一些代码放入属性类本身来加载资源.
Attribute values are hard-coded into the assembly when you compile. If you want to do anything at execution time, you'll need to use a constant as the key, then put some code into the attribute class itself to load the resource.
这篇关于资源文件中的 C# 属性文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)