mscorlib(4.0.0.0) API with additions
SortKey.cs
3 
4 namespace System.Globalization
5 {
8  [ComVisible(true)]
9  public class SortKey
10  {
11  [OptionalField(VersionAdded = 3)]
12  internal string localeName;
13 
14  [OptionalField(VersionAdded = 1)]
15  internal int win32LCID;
16 
17  internal CompareOptions options;
18 
19  internal string m_String;
20 
21  internal byte[] m_KeyData;
22 
25  public virtual string OriginalString => m_String;
26 
29  public virtual byte[] KeyData => (byte[])m_KeyData.Clone();
30 
31  internal SortKey(string localeName, string str, CompareOptions options, byte[] keyData)
32  {
33  m_KeyData = keyData;
34  this.localeName = localeName;
35  this.options = options;
36  m_String = str;
37  }
38 
39  [OnSerializing]
40  private void OnSerializing(StreamingContext context)
41  {
42  if (win32LCID == 0)
43  {
44  win32LCID = CultureInfo.GetCultureInfo(localeName).LCID;
45  }
46  }
47 
48  [OnDeserialized]
49  private void OnDeserialized(StreamingContext context)
50  {
51  if (string.IsNullOrEmpty(localeName) && win32LCID != 0)
52  {
53  localeName = CultureInfo.GetCultureInfo(win32LCID).Name;
54  }
55  }
56 
66  public static int Compare(SortKey sortkey1, SortKey sortkey2)
67  {
68  if (sortkey1 == null || sortkey2 == null)
69  {
70  throw new ArgumentNullException((sortkey1 == null) ? "sortkey1" : "sortkey2");
71  }
72  byte[] keyData = sortkey1.m_KeyData;
73  byte[] keyData2 = sortkey2.m_KeyData;
74  if (keyData.Length == 0)
75  {
76  if (keyData2.Length == 0)
77  {
78  return 0;
79  }
80  return -1;
81  }
82  if (keyData2.Length == 0)
83  {
84  return 1;
85  }
86  int num = (keyData.Length < keyData2.Length) ? keyData.Length : keyData2.Length;
87  for (int i = 0; i < num; i++)
88  {
89  if (keyData[i] > keyData2[i])
90  {
91  return 1;
92  }
93  if (keyData[i] < keyData2[i])
94  {
95  return -1;
96  }
97  }
98  return 0;
99  }
100 
107  public override bool Equals(object value)
108  {
109  SortKey sortKey = value as SortKey;
110  if (sortKey != null)
111  {
112  return Compare(this, sortKey) == 0;
113  }
114  return false;
115  }
116 
119  public override int GetHashCode()
120  {
121  return CompareInfo.GetCompareInfo(localeName).GetHashCodeOfString(m_String, options);
122  }
123 
126  public override string ToString()
127  {
128  return "SortKey - " + localeName + ", " + options + ", " + m_String;
129  }
130  }
131 }
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
virtual byte [] KeyData
Gets the byte array representing the current T:System.Globalization.SortKey object.
Definition: SortKey.cs:29
Definition: __Canon.cs:3
override string ToString()
Returns a string that represents the current T:System.Globalization.SortKey object.
Definition: SortKey.cs:126
static CompareInfo GetCompareInfo(int culture, Assembly assembly)
Initializes a new T:System.Globalization.CompareInfo object that is associated with the specified cul...
Definition: CompareInfo.cs:133
Describes the source and destination of a given serialized stream, and provides an additional caller-...
static CultureInfo GetCultureInfo(int culture)
Retrieves a cached, read-only instance of a culture by using the specified culture identifier.
override int GetHashCode()
Serves as a hash function for the current T:System.Globalization.SortKey object that is suitable for ...
Definition: SortKey.cs:119
static int Compare(SortKey sortkey1, SortKey sortkey2)
Compares two sort keys.
Definition: SortKey.cs:66
Implements a set of methods for culture-sensitive string comparisons.
Definition: CompareInfo.cs:13
override bool Equals(object value)
Determines whether the specified object is equal to the current T:System.Globalization....
Definition: SortKey.cs:107
virtual string OriginalString
Gets the original string used to create the current T:System.Globalization.SortKey object.
Definition: SortKey.cs:25
Represents the result of mapping a string to its sort key.
Definition: SortKey.cs:9
Specifies that the class can be serialized.
virtual int LCID
Gets the culture identifier for the current T:System.Globalization.CultureInfo.
Definition: CultureInfo.cs:304
Provides information about a specific culture (called a locale for unmanaged code development)....
Definition: CultureInfo.cs:16
CompareOptions
Defines the string comparison options to use with T:System.Globalization.CompareInfo.