12 [__DynamicallyInvokable]
21 [OptionalField(VersionAdded = 2)]
22 private string m_name;
25 private string m_sortName;
28 private IntPtr m_dataHandle;
31 private IntPtr m_handleOrigin;
33 [OptionalField(VersionAdded = 1)]
34 private int win32LCID;
38 private const int LINGUISTIC_IGNORECASE = 16;
40 private const int NORM_IGNORECASE = 1;
42 private const int NORM_IGNOREKANATYPE = 65536;
44 private const int LINGUISTIC_IGNOREDIACRITIC = 32;
46 private const int NORM_IGNORENONSPACE = 2;
48 private const int NORM_IGNORESYMBOLS = 4;
50 private const int NORM_IGNOREWIDTH = 131072;
52 private const int SORT_STRINGSORT = 4096;
54 private const int COMPARE_OPTIONS_ORDINAL = 1073741824;
56 internal const int NORM_LINGUISTIC_CASING = 134217728;
58 private const int RESERVED_FIND_ASCII_STRING = 536870912;
60 private const int SORT_VERSION_WHIDBEY = 4096;
62 private const int SORT_VERSION_V4 = 393473;
64 [OptionalField(VersionAdded = 3)]
70 [__DynamicallyInvokable]
71 public virtual string Name 73 [__DynamicallyInvokable]
76 if (m_name ==
"zh-CHT" || m_name ==
"zh-CHS")
88 internal static bool IsLegacy20SortingBehaviorRequested => InternalSortVersion == 4096;
90 private static uint InternalSortVersion
92 [SecuritySafeCritical]
95 return InternalGetSortVersion();
103 [SecuritySafeCritical]
106 if (m_SortVersion ==
null)
108 Win32Native.NlsVersionInfoEx lpNlsVersionInformation =
default(Win32Native.NlsVersionInfoEx);
109 lpNlsVersionInformation.dwNLSVersionInfoSize =
Marshal.
SizeOf(typeof(Win32Native.NlsVersionInfoEx));
110 InternalGetNlsVersionEx(m_dataHandle, m_handleOrigin, m_sortName, ref lpNlsVersionInformation);
111 m_SortVersion =
new SortVersion(lpNlsVersionInformation.dwNLSVersion, (lpNlsVersionInformation.dwEffectiveId != 0) ? lpNlsVersionInformation.dwEffectiveId :
LCID, lpNlsVersionInformation.guidCustomVersion);
113 return m_SortVersion;
119 m_name = culture.m_name;
120 m_sortName = culture.SortName;
121 m_dataHandle = InternalInitSortHandle(m_sortName, out
IntPtr handleOrigin);
122 m_handleOrigin = handleOrigin;
135 if (assembly ==
null)
158 if (name ==
null || assembly ==
null)
174 if (CultureData.IsCustomCultureId(culture))
188 [__DynamicallyInvokable]
214 [SecuritySafeCritical]
222 if (text.Length == 0)
227 return InternalIsSortable(compareInfo.m_dataHandle, compareInfo.m_handleOrigin, compareInfo.m_sortName, text, text.Length);
236 private void OnDeserialized()
238 CultureInfo cultureInfo;
241 cultureInfo = CultureInfo.GetCultureInfo(culture);
242 m_name = cultureInfo.m_name;
246 cultureInfo = CultureInfo.GetCultureInfo(m_name);
248 m_sortName = cultureInfo.SortName;
249 m_dataHandle = InternalInitSortHandle(m_sortName, out IntPtr handleOrigin);
250 m_handleOrigin = handleOrigin;
262 culture = CultureInfo.GetCultureInfo(
Name).LCID;
312 [__DynamicallyInvokable]
313 public virtual int Compare(
string string1,
string string2)
327 [SecuritySafeCritical]
328 [__DynamicallyInvokable]
333 return string.Compare(string1, string2,
StringComparison.OrdinalIgnoreCase);
341 return string.CompareOrdinal(string1, string2);
359 return InternalCompareString(m_dataHandle, m_handleOrigin, m_sortName, string1, 0, string1.Length, string2, 0, string2.Length, GetNativeCompareFlags(options));
376 [__DynamicallyInvokable]
377 public virtual int Compare(
string string1,
int offset1,
int length1,
string string2,
int offset2,
int length2)
395 [__DynamicallyInvokable]
398 return Compare(string1, offset1, (string1 !=
null) ? (string1.Length - offset1) : 0, string2, offset2, (string2 !=
null) ? (string2.Length - offset2) : 0, options);
411 [__DynamicallyInvokable]
412 public virtual int Compare(
string string1,
int offset1,
string string2,
int offset2)
434 [SecuritySafeCritical]
435 [__DynamicallyInvokable]
436 public virtual int Compare(
string string1,
int offset1,
int length1,
string string2,
int offset2,
int length2,
CompareOptions options)
440 int num =
string.Compare(string1, offset1, string2, offset2, (length1 < length2) ? length1 : length2,
StringComparison.OrdinalIgnoreCase);
441 if (length1 != length2 && num == 0)
443 if (length1 <= length2)
451 if (length1 < 0 || length2 < 0)
455 if (offset1 < 0 || offset2 < 0)
459 if (offset1 > (string1?.Length ?? 0) - length1)
463 if (offset2 > (string2?.Length ?? 0) - length2)
492 return CompareOrdinal(string1, offset1, length1, string2, offset2, length2);
494 return InternalCompareString(m_dataHandle, m_handleOrigin, m_sortName, string1, offset1, length1, string2, offset2, length2, GetNativeCompareFlags(options));
498 private static int CompareOrdinal(
string string1,
int offset1,
int length1,
string string2,
int offset2,
int length2)
500 int num =
string.nativeCompareOrdinalEx(string1, offset1, string2, offset2, (length1 < length2) ? length1 : length2);
501 if (length1 != length2 && num == 0)
503 if (length1 <= length2)
523 [SecuritySafeCritical]
524 [__DynamicallyInvokable]
527 if (source ==
null || prefix ==
null)
531 if (prefix.Length == 0)
546 return InternalFindNLSStringEx(m_dataHandle, m_handleOrigin, m_sortName, GetNativeCompareFlags(options) | 0x100000 | ((source.IsAscii() && prefix.IsAscii()) ? 536870912 : 0), source, source.Length, 0, prefix, prefix.Length) > -1;
558 [__DynamicallyInvokable]
559 public virtual bool IsPrefix(
string source,
string prefix)
575 [SecuritySafeCritical]
576 [__DynamicallyInvokable]
579 if (source ==
null || suffix ==
null)
583 if (suffix.Length == 0)
598 return InternalFindNLSStringEx(m_dataHandle, m_handleOrigin, m_sortName, GetNativeCompareFlags(options) | 0x200000 | ((source.IsAscii() && suffix.IsAscii()) ? 536870912 : 0), source, source.Length, source.Length - 1, suffix, suffix.Length) >= 0;
610 [__DynamicallyInvokable]
611 public virtual bool IsSuffix(
string source,
string suffix)
622 [__DynamicallyInvokable]
623 public virtual int IndexOf(
string source,
char value)
639 [__DynamicallyInvokable]
640 public virtual int IndexOf(
string source,
string value)
658 [__DynamicallyInvokable]
665 return IndexOf(source, value, 0, source.Length, options);
678 [__DynamicallyInvokable]
685 return IndexOf(source, value, 0, source.Length, options);
697 public virtual int IndexOf(
string source,
char value,
int startIndex)
716 public virtual int IndexOf(
string source,
string value,
int startIndex)
737 [__DynamicallyInvokable]
744 return IndexOf(source, value, startIndex, source.Length - startIndex, options);
760 [__DynamicallyInvokable]
767 return IndexOf(source, value, startIndex, source.Length - startIndex, options);
782 [__DynamicallyInvokable]
783 public virtual int IndexOf(
string source,
char value,
int startIndex,
int count)
801 [__DynamicallyInvokable]
802 public virtual int IndexOf(
string source,
string value,
int startIndex,
int count)
822 [SecuritySafeCritical]
823 [__DynamicallyInvokable]
830 if (startIndex < 0 || startIndex > source.Length)
834 if (count < 0 || startIndex > source.Length - count)
840 return source.IndexOf(value.ToString(), startIndex, count,
StringComparison.OrdinalIgnoreCase);
846 return InternalFindNLSStringEx(m_dataHandle, m_handleOrigin, m_sortName, GetNativeCompareFlags(options) | 0x400000 | ((source.IsAscii() && value <=
'\u007f') ? 536870912 : 0), source, count, startIndex,
new string(value, 1), 1);
865 [SecuritySafeCritical]
866 [__DynamicallyInvokable]
877 if (startIndex > source.Length)
881 if (source.Length == 0)
883 if (value.Length == 0)
893 if (count < 0 || startIndex > source.Length - count)
899 return source.IndexOf(value, startIndex, count,
StringComparison.OrdinalIgnoreCase);
905 return InternalFindNLSStringEx(m_dataHandle, m_handleOrigin, m_sortName, GetNativeCompareFlags(options) | 0x400000 | ((source.IsAscii() && value.IsAscii()) ? 536870912 : 0), source, count, startIndex, value, value.Length);
914 [__DynamicallyInvokable]
931 [__DynamicallyInvokable]
950 [__DynamicallyInvokable]
957 return LastIndexOf(source, value, source.Length - 1, source.Length, options);
970 [__DynamicallyInvokable]
977 return LastIndexOf(source, value, source.Length - 1, source.Length, options);
989 public virtual int LastIndexOf(
string source,
char value,
int startIndex)
1004 public virtual int LastIndexOf(
string source,
string value,
int startIndex)
1021 [__DynamicallyInvokable]
1024 return LastIndexOf(source, value, startIndex, startIndex + 1, options);
1040 [__DynamicallyInvokable]
1043 return LastIndexOf(source, value, startIndex, startIndex + 1, options);
1058 [__DynamicallyInvokable]
1059 public virtual int LastIndexOf(
string source,
char value,
int startIndex,
int count)
1077 [__DynamicallyInvokable]
1078 public virtual int LastIndexOf(
string source,
string value,
int startIndex,
int count)
1098 [SecuritySafeCritical]
1099 [__DynamicallyInvokable]
1110 if (source.Length == 0 && (startIndex == -1 || startIndex == 0))
1114 if (startIndex < 0 || startIndex > source.Length)
1118 if (startIndex == source.Length)
1126 if (count < 0 || startIndex - count + 1 < 0)
1132 return source.LastIndexOf(value.ToString(), startIndex, count,
StringComparison.OrdinalIgnoreCase);
1134 return InternalFindNLSStringEx(m_dataHandle, m_handleOrigin, m_sortName, GetNativeCompareFlags(options) | 0x800000 | ((source.IsAscii() && value <=
'\u007f') ? 536870912 : 0), source, count, startIndex,
new string(value, 1), 1);
1153 [SecuritySafeCritical]
1154 [__DynamicallyInvokable]
1169 if (source.Length == 0 && (startIndex == -1 || startIndex == 0))
1171 if (value.Length != 0)
1177 if (startIndex < 0 || startIndex > source.Length)
1181 if (startIndex == source.Length)
1188 if (value.Length == 0 && count >= 0 && startIndex - count + 1 >= 0)
1193 if (count < 0 || startIndex - count + 1 < 0)
1199 return source.LastIndexOf(value, startIndex, count,
StringComparison.OrdinalIgnoreCase);
1201 return InternalFindNLSStringEx(m_dataHandle, m_handleOrigin, m_sortName, GetNativeCompareFlags(options) | 0x800000 | ((source.IsAscii() && value.IsAscii()) ? 536870912 : 0), source, count, startIndex, value, value.Length);
1212 return CreateSortKey(source, options);
1223 [SecuritySafeCritical]
1234 byte[] array =
null;
1235 if (
string.IsNullOrEmpty(source))
1237 array = EmptyArray<byte>.Value;
1240 int nativeCompareFlags = GetNativeCompareFlags(options);
1241 int num = InternalGetSortKey(m_dataHandle, m_handleOrigin, m_sortName, nativeCompareFlags, source, source.Length,
null, 0);
1244 throw new ArgumentException(Environment.GetResourceString(
"Argument_InvalidFlag"),
"source");
1248 array =
new byte[num];
1249 num = InternalGetSortKey(m_dataHandle, m_handleOrigin, m_sortName, nativeCompareFlags, source, source.Length, array, array.Length);
1253 source =
string.Empty;
1255 return new SortKey(
Name, source, options, array);
1262 [__DynamicallyInvokable]
1266 if (compareInfo !=
null)
1275 [__DynamicallyInvokable]
1278 return Name.GetHashCode();
1287 [__DynamicallyInvokable]
1297 return source.GetHashCode();
1299 return TextInfo.GetHashCodeOrdinalIgnoreCase(source);
1301 return GetHashCodeOfString(source, options, forceRandomizedHashing:
false, 0
L);
1305 internal int GetHashCodeOfString(
string source,
CompareOptions options)
1307 return GetHashCodeOfString(source, options, forceRandomizedHashing:
false, 0L);
1310 [SecuritySafeCritical]
1311 internal int GetHashCodeOfString(
string source,
CompareOptions options,
bool forceRandomizedHashing,
long additionalEntropy)
1319 throw new ArgumentException(Environment.GetResourceString(
"Argument_InvalidFlag"),
"options");
1321 if (source.Length == 0)
1325 return InternalGetGlobalizedHashCode(m_dataHandle, m_handleOrigin, m_sortName, source, source.Length, GetNativeCompareFlags(options), forceRandomizedHashing, additionalEntropy);
1330 [__DynamicallyInvokable]
1333 return "CompareInfo - " +
Name;
1336 [SecuritySafeCritical]
1337 internal static IntPtr InternalInitSortHandle(
string localeName, out
IntPtr handleOrigin)
1339 return NativeInternalInitSortHandle(localeName, out handleOrigin);
1344 [SuppressUnmanagedCodeSecurity]
1346 private static extern bool InternalGetNlsVersionEx(
IntPtr handle,
IntPtr handleOrigin,
string localeName, ref Win32Native.NlsVersionInfoEx lpNlsVersionInformation);
1350 [SuppressUnmanagedCodeSecurity]
1351 private static extern uint InternalGetSortVersion();
1355 [SuppressUnmanagedCodeSecurity]
1356 private static extern IntPtr NativeInternalInitSortHandle(
string localeName, out
IntPtr handleOrigin);
1360 [SuppressUnmanagedCodeSecurity]
1361 private static extern int InternalGetGlobalizedHashCode(
IntPtr handle,
IntPtr handleOrigin,
string localeName,
string source,
int length,
int dwFlags,
bool forceRandomizedHashing,
long additionalEntropy);
1365 [SuppressUnmanagedCodeSecurity]
1367 private static extern bool InternalIsSortable(
IntPtr handle,
IntPtr handleOrigin,
string localeName,
string source,
int length);
1371 [SuppressUnmanagedCodeSecurity]
1372 private static extern int InternalCompareString(
IntPtr handle,
IntPtr handleOrigin,
string localeName,
string string1,
int offset1,
int length1,
string string2,
int offset2,
int length2,
int flags);
1376 [SuppressUnmanagedCodeSecurity]
1377 private static extern int InternalFindNLSStringEx(
IntPtr handle,
IntPtr handleOrigin,
string localeName,
int flags,
string source,
int sourceCount,
int startIndex,
string target,
int targetCount);
1381 [SuppressUnmanagedCodeSecurity]
1382 private static extern int InternalGetSortKey(
IntPtr handle,
IntPtr handleOrigin,
string localeName,
int flags,
string source,
int sourceCount,
byte[] target,
int targetCount);
Performs reflection on a module.
static CultureInfo InvariantCulture
Gets the T:System.Globalization.CultureInfo object that is culture-independent (invariant).
virtual Assembly Assembly
Gets the appropriate T:System.Reflection.Assembly for this instance of T:System.Reflection....
virtual SortKey GetSortKey(string source)
Gets the sort key for the specified string.
virtual int LastIndexOf(string source, string value, CompareOptions options)
Searches for the specified substring and returns the zero-based index of the last occurrence within t...
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
virtual int LastIndexOf(string source, string value, int startIndex, int count)
Searches for the specified substring and returns the zero-based index of the last occurrence within t...
virtual bool IsSuffix(string source, string suffix)
Determines whether the specified source string ends with the specified suffix.
virtual CompareInfo? CompareInfo
Gets the T:System.Globalization.CompareInfo that defines how to compare strings for the culture.
virtual int GetHashCode(string source, CompareOptions options)
Gets the hash code for a string based on specified comparison options.
virtual int Compare(string string1, int offset1, string string2, int offset2)
Compares the end section of a string with the end section of another string.
StringComparison
Specifies the culture, case, and sort rules to be used by certain overloads of the M:System....
override bool Equals(object value)
Determines whether the specified object is equal to the current T:System.Globalization....
virtual int LastIndexOf(string source, char value, int startIndex, int count, CompareOptions options)
Searches for the specified character and returns the zero-based index of the last occurrence within t...
Indicates that a class is to be notified when deserialization of the entire object graph has been com...
virtual bool IsPrefix(string source, string prefix)
Determines whether the specified source string starts with the specified prefix.
virtual int LastIndexOf(string source, string value, int startIndex, CompareOptions options)
Searches for the specified substring and returns the zero-based index of the last occurrence within t...
The exception that is thrown when the value of an argument is outside the allowable range of values a...
static int SizeOf(object structure)
Returns the unmanaged size of an object in bytes.
virtual int IndexOf(string source, string value, int startIndex)
Searches for the specified substring and returns the zero-based index of the first occurrence within ...
virtual int LastIndexOf(string source, char value, CompareOptions options)
Searches for the specified character and returns the zero-based index of the last occurrence within t...
override int GetHashCode()
Serves as a hash function for the current T:System.Globalization.CompareInfo for hashing algorithms a...
virtual int IndexOf(string source, string value)
Searches for the specified substring and returns the zero-based index of the first occurrence within ...
static CompareInfo GetCompareInfo(int culture, Assembly assembly)
Initializes a new T:System.Globalization.CompareInfo object that is associated with the specified cul...
override string ToString()
Returns a string that represents the current T:System.Globalization.CompareInfo object.
static CompareInfo GetCompareInfo(string name, Assembly assembly)
Initializes a new T:System.Globalization.CompareInfo object that is associated with the specified cul...
virtual int IndexOf(string source, string value, CompareOptions options)
Searches for the specified substring and returns the zero-based index of the first occurrence within ...
virtual int Compare(string string1, int offset1, string string2, int offset2, CompareOptions options)
Compares the end section of a string with the end section of another string using the specified T:Sys...
static CompareInfo GetCompareInfo(int culture)
Initializes a new T:System.Globalization.CompareInfo object that is associated with the culture with ...
virtual int IndexOf(string source, char value, int startIndex, CompareOptions options)
Searches for the specified character and returns the zero-based index of the first occurrence within ...
Describes the source and destination of a given serialized stream, and provides an additional caller-...
virtual int LastIndexOf(string source, char value)
Searches for the specified character and returns the zero-based index of the last occurrence within t...
virtual int IndexOf(string source, string value, int startIndex, CompareOptions options)
Searches for the specified substring and returns the zero-based index of the first occurrence within ...
virtual bool IsSuffix(string source, string suffix, CompareOptions options)
Determines whether the specified source string ends with the specified suffix using the specified T:S...
virtual int Compare(string string1, string string2, CompareOptions options)
Compares two strings using the specified T:System.Globalization.CompareOptions value.
static CultureInfo GetCultureInfo(int culture)
Retrieves a cached, read-only instance of a culture by using the specified culture identifier.
virtual int IndexOf(string source, string value, int startIndex, int count)
Searches for the specified substring and returns the zero-based index of the first occurrence within ...
Provides information about, and means to manipulate, the current environment and platform....
virtual int IndexOf(string source, char value, int startIndex, int count)
Searches for the specified character and returns the zero-based index of the first occurrence within ...
virtual int LastIndexOf(string source, string value, int startIndex, int count, CompareOptions options)
Searches for the specified substring and returns the zero-based index of the last occurrence within t...
Provides information about the version of Unicode used to compare and order strings.
UnmanagedType
Identifies how to marshal parameters or fields to unmanaged code.
void OnDeserialization(object sender)
Runs when the entire object graph has been deserialized.
virtual int IndexOf(string source, char value, int startIndex)
Searches for the specified character and returns the zero-based index of the first occurrence within ...
int LCID
Gets the properly formed culture identifier for the current T:System.Globalization....
virtual int Compare(string string1, string string2)
Compares two strings.
virtual int Compare(string string1, int offset1, int length1, string string2, int offset2, int length2, CompareOptions options)
Compares a section of one string with a section of another string using the specified T:System....
Implements a set of methods for culture-sensitive string comparisons.
Represents an assembly, which is a reusable, versionable, and self-describing building block of a com...
A platform-specific type that is used to represent a pointer or a handle.
virtual int Compare(string string1, int offset1, int length1, string string2, int offset2, int length2)
Compares a section of one string with a section of another string.
virtual int LastIndexOf(string source, char value, int startIndex, int count)
Searches for the specified character and returns the zero-based index of the last occurrence within t...
static CompareInfo GetCompareInfo(string name)
Initializes a new T:System.Globalization.CompareInfo object that is associated with the culture with ...
virtual int IndexOf(string source, string value, int startIndex, int count, CompareOptions options)
Searches for the specified substring and returns the zero-based index of the first occurrence within ...
Provides a collection of methods for allocating unmanaged memory, copying unmanaged memory blocks,...
Represents the version number of an assembly, operating system, or the common language runtime....
virtual string Name
Gets the name of the culture used for sorting operations by this T:System.Globalization....
CharSet
Dictates which character set marshaled strings should use.
virtual int LastIndexOf(string source, char value, int startIndex)
Searches for the specified character and returns the zero-based index of the last occurrence within t...
virtual int IndexOf(string source, char value, int startIndex, int count, CompareOptions options)
Searches for the specified character and returns the zero-based index of the first occurrence within ...
The exception that is thrown when one of the arguments provided to a method is not valid.
virtual int IndexOf(string source, char value)
Searches for the specified character and returns the zero-based index of the first occurrence within ...
Represents the result of mapping a string to its sort key.
virtual bool IsPrefix(string source, string prefix, CompareOptions options)
Determines whether the specified source string starts with the specified prefix using the specified T...
virtual int LastIndexOf(string source, string value, int startIndex)
Searches for the specified substring and returns the zero-based index of the last occurrence within t...
static bool IsSortable(char ch)
Indicates whether a specified Unicode character is sortable.
Specifies that the class can be serialized.
static bool IsSortable(string text)
Indicates whether a specified Unicode string is sortable.
virtual int LCID
Gets the culture identifier for the current T:System.Globalization.CultureInfo.
virtual int LastIndexOf(string source, char value, int startIndex, CompareOptions options)
Searches for the specified character and returns the zero-based index of the last occurrence within t...
Defines text properties and behaviors, such as casing, that are specific to a writing system.
virtual int IndexOf(string source, char value, CompareOptions options)
Searches for the specified character and returns the zero-based index of the first occurrence within ...
Provides information about a specific culture (called a locale for unmanaged code development)....
CompareOptions
Defines the string comparison options to use with T:System.Globalization.CompareInfo.
virtual SortKey GetSortKey(string source, CompareOptions options)
Gets a T:System.Globalization.SortKey object for the specified string using the specified T:System....
virtual int LastIndexOf(string source, string value)
Searches for the specified substring and returns the zero-based index of the last occurrence within t...