1

我有两个大型资源文件,我必须合并它们。两个文件中可能有一些相同的 Name 属性

<data name="SomeResource" xml:space="preserve">
    <value> The resource value </value>
</data>

如何获取所有相同的资源名称?如果有一些具有相同值的条目,那不是问题,但是相同的名称是一个问题。

4

1 回答 1

3

您可以使用一个小型控制台应用程序来获取所有重复的资源名称:

using System;
using System.Collections;
using System.Globalization;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        //replace with your strongly typed resource classes
        var rm1 = MyApplication.Properties.Resources.ResourceManager;
        var rm2 = MyApplication.Properties.Resources1.ResourceManager;

        var rs1 = rm1.GetResourceSet(CultureInfo.CurrentUICulture, true, true);
        var rs2 = rm2.GetResourceSet(CultureInfo.CurrentUICulture, true, true);

        var result = from re1 in rs1.Cast<DictionaryEntry>()
                     join re2 in rs2.Cast<DictionaryEntry>()
                         on re1.Key equals re2.Key
                     select new { re1, re2 };

        foreach (var item in result)
        {
            Console.Write("Key with name \"{0}\" is present in ", 
                item.re1.Key);
            Console.WriteLine("both files (\"{0}\" and \"{1}\")", 
                item.re1.Value, item.re2.Value);
        }
    }
}
于 2013-05-07T10:59:11.963 回答