我在获取正确的资源文件条目时遇到问题,需要一些帮助......这是我的场景
我有一系列项目是遵循这种格式的大型报告解决方案的一部分
插件.****报告
- 参考(文件夹)
- DataAccessLayer(文件夹)
- 数据集(文件夹)
- 数据包装器(文件夹)
本地化(文件夹)
*。CS
其中 * 是我要生成的报告的名称
*.cs 有一个导出语句,以便我可以使用 MEF 获取它(不确定这是否相关,但认为值得一提)。*.cs 中的命名空间是 CompanyName.DataShaper.Plugin.*Report。由于项目名称和文件位置,我将每个项目的默认命名空间更改为 CompanyName.DataShaper.Plugin.*Report(在我更改之前它只是 Plugin.*Report)。
现在对于问题.. 在 *.cs 内部,我正在实例化一个 ResourceManager。看起来像这样...
_resourceManager =
new ResourceManager("CompanyName.DataShaper.Plugin.*Report.Localization.*Report",
Assembly.GetExecutingAssembly());
在我的 resx 设计器文件中,我有以下内容......
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("CompanyName.DataShaper.Plugin.*Report.Localization.*Report", typeof(*Report).Assembly);
resourceMan = temp;
}
return resourceMan;
}
我对资源管理器的调用看起来像这样......
string resourceString = _resourceManager.GetString(resourceKey, _currrentCultureInfo);
其中 _currentCultureInfo 是正确的 CultureInfo 对象。
对于每个项目,我的本地化文件夹中有 4 个不同的 resx 文件(****Report.resx、****Report.fr-ca.resx、****Report.en-gb.resx、*** *Report.de-de.resx)。
当我调用资源管理器时,我总是从 .resx 中获取条目……从来没有任何其他语言文件,无论我传递给调用的 CultureInfo 对象如何。我搞砸了什么?
--> 快速更新我原来的问题,但这似乎与 MEF 相关。我用老式的方式(new *Report())实例化了我的类并进行了本地化调用,它工作正常