Skip to content

Instantly share code, notes, and snippets.

@rhenium
Created June 6, 2012 10:18
Show Gist options
  • Save rhenium/2881157 to your computer and use it in GitHub Desktop.
Save rhenium/2881157 to your computer and use it in GitHub Desktop.
ResX形式のファイルをソートする
using System;
using System.Collections;
using System.Collections.Generic;
using System.Resources;
public class ResXEntry : IComparable
{
private string _key;
private object _value;
public string Key
{
get
{
return _key;
}
}
public object Value
{
get
{
return _value;
}
}
public ResXEntry(string key, object value)
{
this._key = key;
this._value = value;
}
public int CompareTo(object obj)
{
if (obj == null || this.GetType() != obj.GetType())
throw new ArgumentException();
return this.Key.CompareTo(((ResXEntry)obj).Key);
}
}
public class ResXSorter
{
static void Main(string[] args)
{
foreach (string arg in args)
{
List<ResXEntry> entries = new List<ResXEntry>();
using (ResXResourceReader rsxr = new ResXResourceReader(arg))
{
foreach (DictionaryEntry de in rsxr)
entries.Add(new ResXEntry(de.Key.ToString(), de.Value));
}
entries.Sort();
using (ResXResourceWriter rsxw = new ResXResourceWriter(arg))
{
foreach (ResXEntry entry in entries)
rsxw.AddResource(entry.Key, entry.Value);
rsxw.Generate();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment