3

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

developer9969
  • 4,628
  • 6
  • 40
  • 88

1 Answers1

1

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

jomsk1e
  • 3,585
  • 7
  • 34
  • 59
  • thanks for your reply.Would that work using attributes ,I mean calling "resManager.GetString("resourceString") within an attribute.I wish it could be wrapped up to get called like resources.MyName-resources.MySurname etc... – developer9969 Jan 30 '17 at 11:02
  • sorry, now I am confused, don't know what attribute you mean. – jomsk1e Jan 30 '17 at 14:46