c# – .NET如何重命名我的嵌入式资源?

前端之家收集整理的这篇文章主要介绍了c# – .NET如何重命名我的嵌入式资源?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
当我将文件构建为“嵌入式资源”时,Visual Studio会根据其在项目中的路径向其中提供一个名称.例如.我的文件在case / 2013.1 / colours.xml中给出了一个资源名称,其中包含了一些类似于case._2013._1.colours.xml的分布式下划线.

我的问题是 – 这个名字是如何确定的?规则是否记录在案? Visual Studio使用的方法在哪里?

编辑:我问,因为我正在处理大量的这些事情,因此能够从文件路径中推断资源名称是有帮助的.

解决方法

如MSDN Library文章所述,Resgen.exe使用 StronglyTypedResourceBuilder.VerifyResourceName() method实现的规则.我将只复制MSDN库所说的内容

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:

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

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.

查看StronglyTypedResourceBuilder类的源代码,文档准确无误.

原文链接:https://www.f2er.com/csharp/95762.html

猜你在找的C#相关文章