简体   繁体   English

如何从dll c#读取资源文件

[英]How to read resourcefile from dll c#

I would like to use resourcefiles to get some text.These resourcefiles will be in dll.It's nothing todo with localization just in case you ask. 我想使用资源文件来获取一些文本。这些资源文件将在dll中。如果你问的话,它与本地化没什么关系。 I want to have the ability to choose which rexfile to use based on a configsettings. 我希望能够根据配置选择使用哪个rexfile。

Sample MyCompany.RexFiles.dll 示例MyCompany.RexFiles.dll

  1. RexFileA RexFileA
  2. RexFileB RexFileB
  3. RexFileC RexFileC

My question Given that in a config file I have a settings that decide which rexfile to use eg CurrentRexfile="RexFileB" 我的问题鉴于在配置文件中我有一个设置来决定使用哪个rexfile,例如CurrentRexfile =“RexFileB”

How can I default to right rexFile depending on the configSettings. 如何根据configSettings默认为正确的rexFile。

Any suggestions 有什么建议么

You can use the ResourceManager Class to retrieve resources: 您可以使用ResourceManager类来检索资源:

System.Reflection.Assembly myAssembly = this.GetType().Assembly;

string rexFile = ConfigurationManager.AppSettings["CuurentRexfile"];
System.Reflection.Assembly otherAssembly = System.Reflection.Assembly.Load(rexFile);

System.Resources.ResourceManager resManager = new System.Resources.ResourceManager("ResourceNamespace.myResources", otherAssembly);

string test = resManager.GetString("resourceString");

more read here 更多在这里阅读

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM