开发者

Is it possible to define string arrays in .resx resource files?

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开发者_StackOverflow社区 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?


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜