繁体   English   中英

使用非常量字符串作为CategoryAttribute名称

[英]Using a Non-Const String as a CategoryAttribute Name

全部,我正在本地化C#应用程序,并且进入了设置控件。 当我使用PropertyGrid我正在使用属性来提供选项。 我需要使用不同的语言来显示“服务器访问”的CategoryAttribute我有:

[CategoryAttribute("ServerAccess"),
 ReadOnlyAttribute(false),
 XmlElement,
 DescriptionAttribute("Message about the Server Access Option.")]
public bool ShowSystemDatabases 
{
    get { return this.showSystemDatabases; }
    set { this.showSystemDatabases = value; }
}

我试图将其更改为:

[CategoryAttribute(ObjectStrings.SettingsServerAccess),
 ReadOnlyAttribute(false),
 XmlElement,
 DescriptionAttribute(MessageStrings.SettingsShowSystemDatabaseInfo)]
public bool ShowSystemDatabases 
{
    get { return this.showSystemDatabases; }
    set { this.showSystemDatabases = value; }
}

其中ObjectStrings是我的资源文件(“ ObjectStrings.resx”等)。 这会引发编译时错误

An attribute argument must be a constant expression, typeof expression or array 
creation expression of an attribute parameter type...

显然,当构造函数需要const string时,我不能使用const string 我尝试使用各种舍入方法从stringconst string但都失败了。 这是一个非常简单的问题,但是...

解决此问题的最简单方法是什么?

谢谢你的时间。

我不知道如何处理这个问题,尤其是在控件具有属性的情况下,但是实现此目的的一般方法是在运行时使用诸如此类的参数来解析资源:

MessageResourceType = typeof (MyResource), MessageResourceName = "MyResourceKey")

而不是直接将指针传递给资源密钥。

我不知道是否存在等效的CategoryAttribute,DescriptionAttribute和其他控件的属性属性的方法,或者是否有重载它们的方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM