使用 .Resx 文件作为全局应用程序消息?
因此,我对站点内的所有静态消息使用全局资源文件。主要是错误消息等。
它们不需要本地化,但我觉得将它们全部存储在一个位置是一个好主意。
只使用一个名为“SiteConstants”的静态类或其他东西会更好吗?或者使用 RESX 文件可以吗?
谢谢!
So I'm using a Global Resource file for all static messages within my site. Mainly error messages etc..
They do not need to be localized, but I felt it was just a good idea to store them all in one location.
Would it have been better to use just a static class called "SiteConstants" or something? Or is using a RESX file okay?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一定要使用资源文件。
.resx 文件确实会在幕后为您创建类。但最重要的是,自动生成的代码已经为您处理好所有本地化内容。如果您决定本地化您的应用程序,并且使用规定的文件/文件夹结构,也会自动支持这些内容。更不用说本地化您的应用程序只是一个翻译问题,这是最好的情况(更不用说其他本地化问题,例如货币,这是一个完全独立的问题)。
Definitely use resource files.
The .resx files do create classes under the hood for you. Most importantly, though, the auto-generated code will already have all the localization stuff taken care of for you. If you decide to localize your application, there will also be automatic support for that stuff if you use the prescribed file/folder structure. Not to mention that localizing your app will merely be a matter of translation, which is the best-case scenario (not mentioning other localization issues like currency, which is a whole separate issue).
是的,使用资源文件……
这是最常见的消息位置。甚至 Microsoft 也将它们与 .net Framework 一起使用。查看任何 DLL 的内部,您都会发现它们作为资源(使用 .Net Reflector 之类的工具)。
常量通常与低级非托管代码一起使用。
Yes, use resource files …
That's the most common place for messages. Even Microsoft uses them with .net Framework. Look inside any DLL and you'll find them inside as resource (use a tool like .Net Reflector)
Constants are usually used with low level unmanaged code.
在底层,视觉工作室创建了一个设计器文件,它本质上是一个静态的字符串类。所以这两种方法之间不应该有任何区别。请参阅此问题了解更多信息。您应该能够通过在 Visual Studio 中的解决方案资源管理器中打开“显示所有文件”选项来查看设计器文件。
如果您对生成的代码不满意,请查看此页面有关如何自定义生成的代码的信息。
Under the hood visual studio creates a designer file which is essentially a static class of strings. So there shouldn't be any difference between the two approaches. See this question for a bit more information. You should be able to view the designer file by turning on the "show all files" option in the solution explroer in visual studio.
If you're not happy with the code that's generated, check out this page for information on how to customize the generated code.