Getting the ResourceManager from a strongly typed resource file

I had a little bit of difficulty messing around getting the ResourceManager the class generated when making a resource file (resx). I wanted to get the value of something using a string and do it by accessing the ResourceManager property and calling the GetString() method myself. This is what i used to get the resource manager

Note you will need to make the resource file public if referencing as resource file in another assembly.

// Get the ResourceManager on the type
var resourceManager = (ResourceManager)ResourceType.GetProperty(
"ResourceManager",
    System.Reflection.BindingFlags.Public |
System.Reflection.BindingFlags.Static).GetValue(ResourceType, null);

// Get information on the getstring method
return resourceManager.GetString(_resourceKey, CultureInfo.CurrentCulture);

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: