c# - ResXFileCodeGenerator - 覆盖输出(想要使用自定义资源管理器)

标签 c# visual-studio resx

我创建了一个继承自 ResourceManager 的类。我的问题是,如果我更改我的 Resources.Designer.cs 以使用它,

例如

private static global::System.Resources.ResourceManager _resourceManager;

private static global::MyProject.Resources.MyResourceManager _resourceManager;

它被 ResXFileCodeGenerator 覆盖并设置回默认的 System.Resources.ResourceManager

我不想关闭 ResXFileCodeGenerator。但是有没有办法告诉它使用哪个 ResourceManager 类?

我被告知要查看 ResXFileCodeGeneratorEx,但看不出它在这方面有何不同。

最佳答案

有点迟了,但使用反射可以解决这个问题。我将此代码放在 Startup.cs 文件中。

var innerField = typeof(Resources.Resources).GetField("resourceMan",
    BindingFlags.NonPublic | BindingFlags.Static);

if (innerField != null)
{
    innerField.SetValue(null,
        new ExtendedResourceManager("MyNamespace.ResourceFileWithoutResx",
            typeof(Resources.Resources).Assembly));
}

因为设计器生成的文件是公开的,所以只需修改我基于 ResourceManager 编写的代码 { get; } 为您生成的代码。

您可以创建自己的 ExtendedResourceManager 类并根据需要覆盖所有属性。

快乐编码。

关于c# - ResXFileCodeGenerator - 覆盖输出(想要使用自定义资源管理器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35987762/

相关文章:

c# - 动态数据绑定(bind)到转发器或 Datalist 控件,按列

xml - 加载 XML 不工作 : Invalid at the top level of the document

visual-studio - 本地化 resx 文件作为解决方案资源管理器中的子项

javascript - 在 Visual Studio 2010 中运行 javascript 函数时出现无效 ID 错误

.net - MemoryStream 而不是 byte[] 作为资源添加的文件?

c# - 如何强制 Linq 更新一行的上次编辑时间?

c# - 如何调整图像 C#.net Windows 窗体

c# - 根级别的数据无效。第 1 行,位置 1 - 为什么在加载 xml 文件时出现此错误?

C# 如何只读取字节数组[]中选定的值?

c++ - 无法构建 PortAudio - "LNK1104: cannot open file ' ksguid.lib'"