Thursday, 17 April 2014

compare two Resources (.RESX) files using C#

Here is a simple logic to compare two Resources (.RESX) files using C#.

using System;
using System.Collections;
using System.Resources;

namespace ResourceComparer
{
    class Program
    {
        static void Main(string[] args)
        {
            ResXResourceReader rsxr1 = new ResXResourceReader(@"wikiplus.resx");
            ResXResourceReader rsxr2 = new ResXResourceReader(@"wikiplus.de.resx");

            // Iterate through the resources and display the contents
            foreach (DictionaryEntry d1 in rsxr1)
            {
                string value1 = d1.Key.ToString();

                bool secret = false;
                foreach (DictionaryEntry d2 in rsxr2)
                {
                    if (value1.ToString().Equals(d2.Key.ToString(), StringComparison.OrdinalIgnoreCase))
                    {
                        secret = true;
                    }

                    if (secret)
                    {
                        break;
                    }
                }

                if (!secret)
                {
                    Console.WriteLine(d1.Key.ToString());
                }
            }
        }
    }
}

No comments:

Post a Comment