C# - Fastest way to get resource string from assembly
Solution 1
Assembly assembly = this.GetType().Assembly;
ResourceManager resourceManager = new ResourceManager("Resources.Strings", assembly);
string myString = resourceManager.GetString("value");
Solution 2
If the resource is in the same assembly as the code, then the following will do:
String resourceValue = MyAssemblyNameSpace.Properties.Resources.ResourceName
Taken from this SO answer.
Solution 3
string val = Resources.ResourceManager.GetString("resource_name");
Given "resource_name"
you can retrieve resource value.
Solution 4
you can use ResourceManger to get the string value from Assembly
ResourceManager ResManager= new ResourceManager("yourResource",
Assembly.GetExecutingAssembly());
String strResourveValue = ResManager.GetString("YourStringKey");
Solution 5
var thread = System.Threading.Thread.CurrentThread.CurrentUICulture.Name;
var culture = new CultureInfo(thread);
var resourceManager = new ResourceManager(typeof(Resources.Resource));
string value = resourceManager.GetString(name, culture);
Deeptechtons
SOreadytohelp Deeptechtons Programmer, Developer and Enthusiast always looking for chances to learn interesting technology. Meet awesome people and enhance life of people
Updated on July 09, 2022Comments
-
Deeptechtons almost 2 years
I really don't know/have the answer, knowledge to find a resource value using a key from a
resx
file in a assembly using c#.(or may be i am ignorant).What would be the fastest code, way i can retrieve
string values
orvalues
using a key from a resource file which is embedded as resource in a assembly. I am storing friendly messages for exceptions in the resource file and would like to use them when required.Does a static class exist for this purpose?
Are there open source mature projects i can use for this?