.NET是如何重新命名我的嵌入的资源?我的、资源、NET

2023-09-03 03:28:56 作者:忧伤゛染指青春

当我建立一个文件为嵌入的资源,Visual Studio将使它在根据其在项目路径的程序集的名称。例如。我在例/ 2013.1 / colours.xml 被赋予了资源名散发强调像 cases._2013._1.colours.xml 。

When I build a file as 'embedded resource', Visual Studio gives it a name in the assembly depending on its path in the project. Eg. my file at cases/2013.1/colours.xml is given a resource name with sporadic underscores something like cases._2013._1.colours.xml .

我的问题是 - 如何为这个名字确定的?是规则记录?哪里是Visual Studio使用?

My question is - how does is this name determined? Are the rules documented? Where is the method that Visual Studio uses?

编辑:我想问,因为我正在与大量的这些事情,这将是能够从文件路径推断资源名有益

I ask because I'm working with a large number of these things and it would be helpful to be able to deduce the resource name from the file path.

推荐答案

由于记录在MSDN Library文章,Resgen.exe使用由StronglyTypedResourceBuilder.VerifyResourceName()法。我就复制一下MSDN库说:

As documented by the MSDN Library article, Resgen.exe uses the rules implemented by the StronglyTypedResourceBuilder.VerifyResourceName() method. I'll just copy what the MSDN library says:

如果关键参数为空字符串(),则返回一个字符串,由一个单一的下划线(_)的。如果密钥参数不是一个空字符串,VerifyResourceName方法的字符串中的每个字符与一组基于提供商参数指定的语言无效标记。任何无效字符的字符串替换为下划线。是将被替换为下划线的文字如下:

If the key parameter is an empty string (""), a string that consists of a single underscore character (_) is returned. If the key parameter is not an empty string, the VerifyResourceName method compares each character in the string to a set of invalid tokens based on the language specified by the provider parameter. Any invalid character in the string is replaced with an underscore character. The characters that will be replaced with an underscore are as follows:

(空格),U + 00A0(不间断空格),'。' (期),,(逗号),; (分号),|,〜,@,#,%,^,&安培;','*','+',' - ','/',' \','&所述;','>','','[',']','(,),{,},'(报价),''' (单引号),':''!',以及

' ' (space), U+00A0 (non-breaking space), '.' (period), ',' (comma), ';' (semicolon), '|', '~', '@', '#', '%', '^', '&', '*', '+', '-', '/', '\', '<', '>', '?', '[', ']', '(', ')', '{', '}', '"' (quote), ''' (apostrophe), ':', and '!'.

注意   强类型资源不允许使用语言的关键字(如if,for和等)的资源键名称。然而,系统。codeDOM设计模式允许使用的语言关键字由prefixing有下划线的关键字。该VerifyResourceName方法调用CreateValidIdentifier方法来执行这项设计。例如,如果使用的是相同的一种语言的关键字,诸如用于一个资源名称,该名称显示为_for在生成的强类型资源类

Note Strongly-typed resources do not allow the use of language keywords (such as if, for, and so on) as resource key names. However, the System.CodeDom design pattern allows the use of language keywords by prefixing the keyword with the underscore character. The VerifyResourceName method calls the CreateValidIdentifier method to enforce this design. For example, if you use a resource name that is the same as a language keyword, such as for, the name appears as _for in the generated strongly-typed resource class.

查看源$ C ​​$ C为StronglyTypedResourceBuilder类,文档是准确的。

Looking at the source code for the StronglyTypedResourceBuilder class, the documentation is accurate.