资源字符串位置 [英] Resource String Location

查看:183
本文介绍了资源字符串位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在哪里是将资源字符串的最佳位置?这是否取决于范围有多大?目前,我国大部分字符串都被放置在项目层面,但只需要一种形式的某些字符串。我的想法是,这些字符串应该尽可能地靠近他们尽可能使用。

Where is the best location to place resource strings? Does it depend on scope? Currently most of our strings are being placed at the project level, but certain strings are only needed for one form. My thoughts would be that these strings should be placed as close to their use as possible.

推荐答案

下面是我做(并不一定是最好的方式,但它的工作很好,到目前为止),用于将编程字符串,除了采用直接在语言敏感字符串形式:

Here's what I do (not necessarily the best way, but it's worked well so far) for adding programmatic strings, in addition to using language-sensitive strings directly on forms:

除了通过表单添加文件夹荒谬的数字到项目组,我一直没能找到一个干净的解决方案不是将自己的资源文件夹中的.resx文件等。通常我会碰到这样的:

Aside from adding a ridiculous number of folders into the project to group by form, I haven't been able to find a clean solution other than keeping the .resx files in their own Resources folder. Usually I'll have something like:

资源\语言
资源\ XML
资源\图像
等等。

Resources\Language
Resources\Xml
Resources\Images
etc.

我发现,使用每形成一个.resx文件是最好的方式,因为你永远不知道什么时候你将需要添加另一个字符串。我还创建Common.resx字符串如保存,负载,等等,这是适用于整个申请,并在多个点将被使用。随着一的.resx每表单模型,你必须要严格地限制只能使用字符串的形式,这可能意味着重复弦数,一路上为您的应用程序的增长。但是,这是更容易比有形式和.resx文件之间的引用的蜘蛛网维护。

I've found that using one .resx file per form is the best way to go, because you never know when you're going to need to add another string. I also create a Common.resx for strings such as "Save", "Load", etc., that are applicable to the whole application and will be used in multiple spots. With the one-.resx-per-form model, you have to be strict about only using strings in that form, which will probably mean repeating a few strings along the way as your application grows. But this is far easier to maintain than having a spiderweb of references between forms and .resx files.

有关自定义控件,我把.resx文件与源文件,因为它们通常有自己的文件夹,该字符串将不会是自定义的控制范围之内无论如何使用。 (注:这也意味着自定义的控制不应该超出其自身的.resx文件中使用的字符串)。这也将让您轻松地在必要时提取的整体自定义控件到一个单独的程序集

For custom controls, I put the .resx files with the source files, since they usually have their own folder, and the strings won't be used outside that custom control anyway. (Note: this also means the custom controls should NOT use strings outside its own .resx file.) This will also allow you to easily extract a whole custom control into a separate assembly if necessary.

有关用户控件,通常他们是应用特定的,所以它不是那么糟糕追平了共同语言的东西给它,但肯定我会使用特定于用户控制线单独的.resx,并遵循相同的文件夹结构与自定义控件。

For user controls, usually they're application-specific, so it's not so bad tying the common language stuff to it, but certainly I'll use a separate .resx for strings specific to the user control, and follow the same folder structure as with the custom controls.

这篇关于资源字符串位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆