<Compile Include="$(MSBuildThisFileDirectory)System\Globalization\DaylightTime.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Globalization\DigitShapes.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Globalization\EastAsianLunisolarCalendar.cs" />
+ <Compile Include="$(MSBuildThisFileDirectory)System\Globalization\GlobalizationExtensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Globalization\GregorianCalendar.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Globalization\GregorianCalendarHelper.cs" />
<Compile Include="$(MSBuildThisFileDirectory)System\Globalization\GregorianCalendarTypes.cs" />
--- /dev/null
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Diagnostics;
+
+namespace System.Globalization
+{
+ public static class GlobalizationExtensions
+ {
+ public static StringComparer GetStringComparer(this CompareInfo compareInfo, CompareOptions options)
+ {
+ if (compareInfo == null)
+ {
+ throw new ArgumentNullException(nameof(compareInfo));
+ }
+
+ if (options == CompareOptions.Ordinal)
+ {
+ return StringComparer.Ordinal;
+ }
+
+ if (options == CompareOptions.OrdinalIgnoreCase)
+ {
+ return StringComparer.OrdinalIgnoreCase;
+ }
+
+ return new CultureAwareComparer(compareInfo, options);
+ }
+ }
+}
private readonly CompareInfo _compareInfo; // Do not rename (binary serialization)
private CompareOptions _options;
- internal CultureAwareComparer(CultureInfo culture, CompareOptions compareOptions)
+ internal CultureAwareComparer(CultureInfo culture, CompareOptions options) : this(culture.CompareInfo, options) { }
+
+ internal CultureAwareComparer(CompareInfo compareInfo, CompareOptions options)
{
- _compareInfo = culture.CompareInfo;
+ _compareInfo = compareInfo;
- if ((compareOptions & CultureAwareComparer.ValidCompareMaskOffFlags) != 0)
+ if ((options & ValidCompareMaskOffFlags) != 0)
{
- throw new ArgumentException(SR.Argument_InvalidFlag, nameof(compareOptions));
+ throw new ArgumentException(SR.Argument_InvalidFlag, nameof(options));
}
- _options = compareOptions;
+ _options = options;
}
private CultureAwareComparer(SerializationInfo info, StreamingContext context)