是否可以在 .resx 资源文件中定义字符串数组?

发布于 2024-09-16 11:24:41 字数 319 浏览 6 评论 0原文

目前,我这样做:

Names -> "name1|name2|name3"

Resource.Names.Split('|');

是否可以将这些名称定义为资源文件中的数组,以便我不必每次都通过拆分进行解析?

也许像下面这样?

Names[] -> "name1"
Names[] -> "name2"
Names[] -> "name3"
Resource.Names; // is of type string[]

也许还有另一种更好的方法吗?

Currently, I do this:

Names -> "name1|name2|name3"

Resource.Names.Split('|');

Is it possible to define those names as an array in the resource file so that I don't have to parse by splitting every time?

Something like the following perhaps?

Names[] -> "name1"
Names[] -> "name2"
Names[] -> "name3"
Resource.Names; // is of type string[]

Is there perhaps another, better way?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

浮生面具三千个 2024-09-23 11:24:41

根据 MSDN ResXResourceWriter页面可以使用那里提供的代码生成此类资源。字符串和数组都是可序列化类型,但是资源当然包含 Base64 编码的序列化数组表示,它不容易读写。但这是可能的,并且在添加生成的 resx 文件时可以正确检测类型。我使用以下代码进行测试:

using System.Resources;

internal class Program
{
    private static void Main(string[] args)
    {
        var arr = new[] { "Test", "string", "array", "resources" };

        using (var writer = new ResXResourceWriter("./output.resx"))
        {
            writer.AddResource("strings", arr);
            writer.Generate();
        }
    }
}

也就是说,不,如果没有额外的自定义,就不可能以人类可读的形式在资源文件中定义字符串数组。

According to MSDN ResXResourceWriter page one can generate such resources using code provided there. Both string and array are serializable types, but of course resources contain Base64-encoded serialized array representation, which is not readable or writeable easily. But it is possible, and the type is detected correctly when adding generated resx file. I've used the following code to test:

using System.Resources;

internal class Program
{
    private static void Main(string[] args)
    {
        var arr = new[] { "Test", "string", "array", "resources" };

        using (var writer = new ResXResourceWriter("./output.resx"))
        {
            writer.AddResource("strings", arr);
            writer.Generate();
        }
    }
}

That said, no, it is not possible to have string array defined inside resource file in human-readable form without additional customizations.

猥︴琐丶欲为 2024-09-23 11:24:41

您可以使用应用程序设置来存储阵列。
转到您的应用程序属性,然后转到设置选项卡。您可以设置设置的名称,选择所需的类型、范围和值。

有关详细信息:http://msdn.microsoft。 com/en-us/library/aa730869%28VS.80%29.aspx

You can use the app settings to store your arrays.
Go to your apps properties then the settings tab. You can set the name of your setting, select what type you want, the scope and the values.

For more info: http://msdn.microsoft.com/en-us/library/aa730869%28VS.80%29.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文