使用 *.resx 文件存储字符串值对
我有一个需要字符串值之间映射的应用程序,因此本质上是一个可以保存键值对的容器。我没有使用字典或名称-值集合,而是使用了在代码中以编程方式访问的资源文件。据我所知,资源文件用于多语言实现等本地化场景。不过,我喜欢它们的强类型特性,这可以确保如果值发生更改,应用程序将无法编译。
但是我想知道使用 *.resx 文件进行简单的键值对存储而不是使用更传统的编程类型是否有任何重要的缺点。
I have an application that requires mappings between string values, so essentially a container that can hold key values pairs. Instead of using a dictionary or a name-value collection I used a resource file that I access programmatically in my code. I understand resource files are used in localization scenarios for multi-language implementations and the likes. However I like their strongly typed nature which ensures that if the value is changed the application does not compile.
However I would like to know if there are any important cons of using a *.resx file for simple key-value pair storage instead of using a more traditional programmatic type.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我突然想到了两个缺点:
顺便提一句。难道您不能只创建包含属性的帮助器类或结构吗,如下所示:
然后您可以以与资源文件完全相同的方式访问这些属性(我假设您已经习惯了这种样式):
也许它不是最好的要做的事情,但我坚信这仍然比使用资源文件更好......
There are two cons which I can think of out of the blue:
BTW. Couldn't you just create helper class or structure containing properties, like that:
You can then access these properties exactly the same way, as resource files (I am assuming that you're used to this style):
Maybe it is not the best thing to do, but I firmly believe this is still better than using resource file for that...