Using .Resx files for global application messages?

依然范特西╮ 提交于 2019-11-28 05:03:58

问题


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!


回答1:


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).




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/1820912/using-resx-files-for-global-application-messages

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!