How can I read embedded .resx in different assembly

倖福魔咒の 提交于 2019-12-11 09:16:50

问题


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.


回答1:


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




回答2:


You need to load the assembly first:

Assembly ressourceAssembly = Assembly.Load("ResourceAssembly");

(There are a couple of issues you could have with this. Read about dynamic assembly loading specificly.)

Then create the resource manager:

ResourceManager myManager = new 
   ResourceManager("<default namespace>.<Resx-Folder>.<Resx-File>", ressourceAssembly);

Then load the string:

myManager.GetString("FirstNameTooltip");


来源:https://stackoverflow.com/questions/30724195/how-can-i-read-embedded-resx-in-different-assembly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!