Why is it better to name the ResourceManager class rather than loading resources directly by name?

I worked on localizing a large project, and I did this by manually creating a large resource file and calling each line by name in the code. Instead of calling ResourceManager and using GetString (for dialogs, etc.) I simply replaced each line with Resources.ClassName_MethodName_StringName .

I have a feeling that I should use the ResourceManager , but I want to understand why this is better before I modify all my code to use it.

+7
source share
2 answers

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

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

This is great, as you get a free confirmation of your resource names at compile time!

+9
source

http://www.c-sharpcorner.com/uploadfile/prvn_131971/chapter-i-resources-and-localization/

Internally, the generated class uses an instance of the ResourceManager class, which is defined in the System.Resources Namespace. An instance of this class is available through the created ResourceManager class. The intrinsic property of the procedure for accessing embedded resources themselves is a wrapper around calls to one of the GetXxx methods (i.e. GetString or GetStream) of this ResourceManager instance. For example, a resource that is accessible using the procedure of the generated Property.MyResourceStrings property.

Thus, by invoking resources directly by name, you still use the YourResources.ResourceManager.GetString () method.

0
source

All Articles