在resx属性中,我将自定义工具命名空间从
正如您所看到的,只有类命名空间被更改了,而没有更改在 ResourceManager 构造函数中传递的命名空间。因此,当我实例化 ResourceManager(typeof(CommentResources)) 并尝试访问一个键时,它会抛出 MissingManifestResourceException 异常,例如:
我该如何真正更改命名空间?
编辑:
请查看下面我的解决方案。每当我在“环境”文件夹中创建一个resx文件时,它都会创建一个不需要的命名空间。这就是我想要避免的。
DefaultNamespace
更改为MyNamespace.Language
,生成以下代码:namespace MyNamespace.Language
{
public class CommentResources
{
public static global::System.Resources.ResourceManager ResourceManager {
get {
//removed code...
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DefaultNamespace.CommentResources", typeof(CommentResources).Assembly);
}
}
正如您所看到的,只有类命名空间被更改了,而没有更改在 ResourceManager 构造函数中传递的命名空间。因此,当我实例化 ResourceManager(typeof(CommentResources)) 并尝试访问一个键时,它会抛出 MissingManifestResourceException 异常,例如:
var manager = new ResourceManager(typeof(CommentResources));
var resource = manager.GetString("myKey");
我该如何真正更改命名空间?
编辑:
请查看下面我的解决方案。每当我在“环境”文件夹中创建一个resx文件时,它都会创建一个不需要的命名空间。这就是我想要避免的。
Enviroment
的文件夹,我不能把它作为命名空间的一部分,因为你知道,“Enviroment”已经是一个类。那只是一个例子,还有其他几个类似的文件夹。 - JobaDiniz