覆盖.resx文件中的Name值 [英] Override the Name value in .resx files

查看:102
本文介绍了覆盖.resx文件中的Name值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义表单网格控件,它有一个collection属性,其中包含有两个字符串属性设置为本地化的对象。这可以按预期工作,除了.resx文件中使用的Name(密钥)太通用了。例如,它将Name指定为resource.Label,resource.Label1,resource.Label2。当一个条目被添加到集合中时会出现问题,因为所有内容都已移位,因此从.resx文件中解析出错误的值。



有没有办法挂钩进入.resx写入过程并以这种方式自定义键(名称字段中使用的值)?我希望能够将其设置为网格的名称+字段名称(该集合基本上是字段的集合),例如, grdOrder.OrdNum.Label。



提前致谢,



Trausti



看起来我没有清楚地解释这种情况。



这是网格中的集合属性:



I have a custom forms grid control that has a collection property which contains object which has two string properties set to be localized. This works as expected, except the Name (the key) used in the .resx file is too generic. As an example, it will assign the Name to be resource.Label, resource.Label1, resource.Label2. This becomes a problem when an entry is added to the collection as everything is shifted and therefore incorrect values are resolved from the .resx file.

Is there any way to hook into the .resx writing process and in that way customize the key (the value used in the Name field)? I am hoping to be able to set this to be the grid's name + field name (the collection is basically a collection of fields), e.g. grdOrder.OrdNum.Label.

Thanks in advance,

Trausti

Looks like I did not explain the situation clearly enough.

Here is the collection property in the grid:

Description("Collection of Column Info objects"), _
Category("Oppenheimer Properties"), _
DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
Public ReadOnly Property ColumnInfo() As ColumnInfoCollection
    Get
        If columnInfos Is Nothing Then
            columnInfos = New ColumnInfoCollection
        End If
        Return columnInfos
    End Get
End Property





此集合包含由键(字符串)和另一个名为DataLink的对象组成的对象。 DataLink对象包含多个属性,其中一个属性已本地化:





This collection contains objects which are made up of key (string) and another object called DataLink. The DataLink object contains number of properties, of which one is localized:

Description("Label of the field"), _
DefaultValue(""), _
Localizable(True), _
Category("Oppenheimer Properties"), _
NotifyParentProperty(True)> _
Property Label() As String
    Get
        Return lbl
    End Get
    Set(ByVal Value As String)
        lbl = Value
    End Set
End Property



假设我的ColInfo集合中有3个DataLink对象。在.resx文件中,VS将使用resource.Label,resource.label1和resource.label2。这是我的问题。



再次,简而言之,我想知道是否有人知道,在设计师级别,我是否可以在.resx文件中提供VS使用的密钥。


Let's say I have 3 DataLink objects in my ColInfo collection. In the .resx file VS will use resource.Label, resource.label1 and resource.label2. This is my problem.

Again, in short, I am asking if somebody knows if, on designer level, I can provide the key used by VS in the .resx files.

推荐答案

我认为你的方向是错误的。你不应该使用标签名称Label,Label1,Label2等。这样的名称违反了(良好的)Microsoft命名约定,这些约定不允许任何名称中的数字,下划线和缩写,出于某些非常好的理由。所有名称都应正确拼写并且语义敏感。如果您遵循这些约定,您也不会遇到资源名称问题。



顺便提一下,设计师会生成许多违反这些约定的名称。这很自然:设计师不知道你的语义。但是为什么你认为Visual Studio提供了一个重构引擎?对于设计师来说,这些错误的名称甚至是方便的:当你看到这样的名字时,它表明你还没有碰到那些物品,它们仍然需要注意。当你使用这些对象时,使用重构引擎重命名它们。



-SA
I think you are going in a wrong direction. You should never use, say, label names "Label", "Label1", "Label2" or the like. Such name violate (good) Microsoft naming conventions which don't allow, in particular, digits, underscores and abbreviations in any names, for some really good reasons. All names should be properly spelled and be semantically sensitive. If you follow these conventions, you won't face problems with resource names as well.

By the way, many names violating those conventions are generated by the designer. It's only natural: the designer "knows" nothing about your semantic. But why do you think Visual Studio provides a refactoring engine for? With the designer, those "wrong" names are even convenient: when you see such name, it indicates that you did not touch those objects yet and they are still need attention. Rename them using the refactoring engine as you come to using such objects.

—SA


这篇关于覆盖.resx文件中的Name值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆