CultureInfoComparer.cs
1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Globalization;
namespace Resx2Xls
{
public class CultureInfoComparer : IComparer
{
// Methods
public int Compare(object x, object y)
{
if (((x == null) && (y == null)) || x.Equals(y))
{
return 0;
}
if (x.Equals(CultureInfo.InvariantCulture) || (y == null))
{
return -1;
}
if (y.Equals(CultureInfo.InvariantCulture) || (x == null))
{
return 1;
}
if (!(x is CultureInfo))
{
throw new ArgumentException("Can only compare CultureInfo objects.", "x");
}
string displayName = ((CultureInfo)x).DisplayName;
if (!(y is CultureInfo))
{
throw new ArgumentException("Can only compare CultureInfo objects.", "y");
}
string strB = ((CultureInfo)y).DisplayName;
return displayName.CompareTo(strB);
}
}
}