如何在不同程序集中读取嵌入式.resx [英] How can I read embedded .resx in different assembly

查看:93
本文介绍了如何在不同程序集中读取嵌入式.resx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有一些dll,它们仅包含许多.resx文件作为嵌入式资源.在每个项目中,.resx文件都放在不同的文件夹中.全部的自定义工具名称空间"属性设置为每个项目的名称空间. 当我尝试使用ResourceManager来获取字符串时,出现错误,例如找不到"MyTemplate.resources",但dll中仅包含"MyTemplate.resx".

我如何访问我的资源?

new ResourceManager(typeof(MyTemplate.resx)).GetString("FirstNameTooltip");

正如我在下面的评论中所说,资源是动态变化的.而且我无法直接访问其属性.

解决方案

这是我通常的操作方式:

string mystring = YourResourceNamespace.MyTemplate.FirstNameTooltip;

如果您不知道napespace,请单击.resx并双击Designer.cs,然后检查名称空间,所有关键字都被定义为带有gettor的简单静态变量,因此只需调用这些关键字即可./p>

如果资源位于另一个项目中,则只需将其包含在您的项目中即可从您的项目中访问它们.

我希望这对您有帮助

I have some dlls in my project that only contain many .resx files as embedded resources. In each project the .resx files are put into different folders. The property "Custom Tool Name Space" of all is set to the namespace of each project. When I try to use ResourceManager to get a string I get an error that for example "MyTemplate.resources" is not found but I only have "MyTemplate.resx" in the dll.

How can I access my resources?

new ResourceManager(typeof(MyTemplate.resx)).GetString("FirstNameTooltip");

As I said in comment below the Resources are dynamicly changed. and i have no direct access to its properties.

解决方案

Here's how I usually do:

string mystring = YourResourceNamespace.MyTemplate.FirstNameTooltip;

If you don't know the napespace, click on the .resx and double click on the Designer.cs, then check the namespace, all the keywords are defined as simple static variable with gettor, so just call those ones.

If ressource is in one other project, then simply incude it onto your project in order to access them from your project.

I hope this helps

这篇关于如何在不同程序集中读取嵌入式.resx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆