Skip to content
This repository was archived by the owner on Nov 1, 2020. It is now read-only.

Commit 7395ce5

Browse files
Anipikdotnet-bot
authored andcommitted
Moved extensions.cs to shared folder in coreclr (dotnet/coreclr#16459)
* Moved extensions.cs to shared folder * added to shared to projItems * Added new constructor * Parameter Named Changed Signed-off-by: dotnet-bot <dotnet-bot@microsoft.com>
1 parent 94b4f26 commit 7395ce5

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

src/System.Private.CoreLib/shared/System.Private.CoreLib.Shared.projitems

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
<Compile Include="$(MSBuildThisFileDirectory)System\Globalization\DaylightTime.cs" />
150150
<Compile Include="$(MSBuildThisFileDirectory)System\Globalization\DigitShapes.cs" />
151151
<Compile Include="$(MSBuildThisFileDirectory)System\Globalization\EastAsianLunisolarCalendar.cs" />
152+
<Compile Include="$(MSBuildThisFileDirectory)System\Globalization\GlobalizationExtensions.cs" />
152153
<Compile Include="$(MSBuildThisFileDirectory)System\Globalization\GregorianCalendar.cs" />
153154
<Compile Include="$(MSBuildThisFileDirectory)System\Globalization\GregorianCalendarHelper.cs" />
154155
<Compile Include="$(MSBuildThisFileDirectory)System\Globalization\GregorianCalendarTypes.cs" />
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Diagnostics;
7+
8+
namespace System.Globalization
9+
{
10+
public static class GlobalizationExtensions
11+
{
12+
public static StringComparer GetStringComparer(this CompareInfo compareInfo, CompareOptions options)
13+
{
14+
if (compareInfo == null)
15+
{
16+
throw new ArgumentNullException(nameof(compareInfo));
17+
}
18+
19+
if (options == CompareOptions.Ordinal)
20+
{
21+
return StringComparer.Ordinal;
22+
}
23+
24+
if (options == CompareOptions.OrdinalIgnoreCase)
25+
{
26+
return StringComparer.OrdinalIgnoreCase;
27+
}
28+
29+
return new CultureAwareComparer(compareInfo, options);
30+
}
31+
}
32+
}

src/System.Private.CoreLib/shared/System/StringComparer.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,17 @@ public sealed class CultureAwareComparer : StringComparer, ISerializable
179179
private readonly CompareInfo _compareInfo; // Do not rename (binary serialization)
180180
private CompareOptions _options;
181181

182-
internal CultureAwareComparer(CultureInfo culture, CompareOptions compareOptions)
182+
internal CultureAwareComparer(CultureInfo culture, CompareOptions options) : this(culture.CompareInfo, options) { }
183+
184+
internal CultureAwareComparer(CompareInfo compareInfo, CompareOptions options)
183185
{
184-
_compareInfo = culture.CompareInfo;
186+
_compareInfo = compareInfo;
185187

186-
if ((compareOptions & CultureAwareComparer.ValidCompareMaskOffFlags) != 0)
188+
if ((options & ValidCompareMaskOffFlags) != 0)
187189
{
188-
throw new ArgumentException(SR.Argument_InvalidFlag, nameof(compareOptions));
190+
throw new ArgumentException(SR.Argument_InvalidFlag, nameof(options));
189191
}
190-
_options = compareOptions;
192+
_options = options;
191193
}
192194

193195
private CultureAwareComparer(SerializationInfo info, StreamingContext context)

0 commit comments

Comments
 (0)