简体   繁体   中英

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. I want to have the ability to choose which rexfile to use based on a configsettings.

Sample MyCompany.RexFiles.dll

  1. RexFileA
  2. RexFileB
  3. RexFileC

My question Given that in a config file I have a settings that decide which rexfile to use eg CurrentRexfile="RexFileB"

How can I default to right rexFile depending on the configSettings.

Any suggestions

You can use the ResourceManager Class to retrieve resources:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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