Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# - Fastest way to get resource string from assembly

Tags:

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 or values 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?

like image 472
Deeptechtons Avatar asked Jan 24 '12 05:01

Deeptechtons


2 Answers

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.

like image 174
herzbube Avatar answered Sep 22 '22 08:09

herzbube


Assembly assembly = this.GetType().Assembly; ResourceManager resourceManager = new ResourceManager("Resources.Strings", assembly); string myString = resourceManager.GetString("value"); 
like image 35
sblom Avatar answered Sep 19 '22 08:09

sblom