我正在寻找一种本地化PropertyGrid中显示的属性名称的方法。使用DisplayNameAttribute属性可以将该属性的名称“覆盖”。不幸的是,属性不能具有非常量表达式。因此,我不能使用强类型资源,例如:
class Foo
{
[DisplayAttribute(Resources.MyPropertyNameLocalized)] // do not compile
string MyProperty {get; set;}
}
我环顾四周,发现一些建议可以从DisplayNameAttribute继承来使用资源。我最终会得到如下代码:
class Foo
{
[MyLocalizedDisplayAttribute("MyPropertyNameLocalized")] // not strongly typed
string MyProperty {get; set;}
}
但是,我失去了强类型资源的好处,这绝对不是一件好事。然后我遇到了DisplayNameResourceAttribute,这可能是我想要的。但这应该在Microsoft.VisualStudio.Modeling.Design命名空间中,而我找不到应该为该命名空间添加的引用。
有人知道是否有一种简便的方法可以很好地实现DisplayName本地化?或者是否可以使用Microsoft似乎在Visual Studio中使用的方式?
呼如林
UYOU
相关分类