Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is it better to call the ResourceManager class as opposed to loading resources directly by name?

I was working on localizing a large project, and I was doing that by creating a large resource file manually, and calling each string by name in the code. Instead of calling the ResourceManager and using GetString (for dialog boxes, etc), I was simply replacing each string by Resources.ClassName_MethodName_StringName.

I have a feeling I'm supposed to be using the ResourceManager, but I want to understand why it's better before I change all of my code to use it.

like image 494
terrafv Avatar asked Jan 24 '13 13:01

terrafv


1 Answers

Well, there's no reason to use the ResourceManager directly (some exceptions to that will apply), because if you use generated code from the resx-Files all it does is the following:

public static string MyResourceName {
    get {
        return ResourceManager.GetString("MyResourceName", resourceCulture);
    }
}

This is great, since you get Compile-Time validation of your resource-names for free!

like image 77
TGlatzer Avatar answered Nov 08 '22 12:11

TGlatzer