为什么它更好地调用ResourceManager类直接通过名字而不是加载资源? [英] Why is it better to call the ResourceManager class as opposed to loading resources directly by name?
问题描述
我工作的定位一个大的项目,我是这样做,通过手动创建一个大的资源文件,并调用代码中的每个串的名字。而不是调用的的ResourceManager
,并使用的GetString
(对于对话框,等等),我只是通过更换每个字符串 Resources.ClassName_MethodName_StringName
。
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
.
我有一种感觉,我应该可以使用的ResourceManager
,但我想知道为什么它更好之前,我改变了我所有的代码来使用它。
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.
推荐答案
那么,有没有理由直接使用ResourceManager(一些例外情况将适用),因为如果你使用来自RESX档案生成的代码它是所有以下内容:
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!
这篇关于为什么它更好地调用ResourceManager类直接通过名字而不是加载资源?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!