diff options
author | Anirudh Agnihotry <anirudhagnihotry098@gmail.com> | 2018-02-20 21:01:39 -0800 |
---|---|---|
committer | Jan Kotas <jkotas@microsoft.com> | 2018-02-20 21:01:39 -0800 |
commit | 8ee398e52432eae5ce4722d4e621f81ad12d6591 (patch) | |
tree | 075e3dd503a0a8a0d2227009fd19b1f8fa151e46 | |
parent | bab1d4a8fc1e48144bd75faeed8845996fa4c4db (diff) | |
download | coreclr-8ee398e52432eae5ce4722d4e621f81ad12d6591.tar.gz coreclr-8ee398e52432eae5ce4722d4e621f81ad12d6591.tar.bz2 coreclr-8ee398e52432eae5ce4722d4e621f81ad12d6591.zip |
Moved extensions.cs to shared folder in coreclr (#16459)
* Moved extensions.cs to shared folder
* added to shared to projItems
* Added new constructor
* Parameter Named Changed
3 files changed, 40 insertions, 5 deletions
diff --git a/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems b/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems index 7e7fc2895b..d0dc4394b4 100644 --- a/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems +++ b/src/mscorlib/shared/System.Private.CoreLib.Shared.projitems @@ -149,6 +149,7 @@ <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" /> diff --git a/src/mscorlib/shared/System/Globalization/GlobalizationExtensions.cs b/src/mscorlib/shared/System/Globalization/GlobalizationExtensions.cs new file mode 100644 index 0000000000..007283aa6b --- /dev/null +++ b/src/mscorlib/shared/System/Globalization/GlobalizationExtensions.cs @@ -0,0 +1,32 @@ +// 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); + } + } +} diff --git a/src/mscorlib/shared/System/StringComparer.cs b/src/mscorlib/shared/System/StringComparer.cs index b5f20c9570..de311e91d1 100644 --- a/src/mscorlib/shared/System/StringComparer.cs +++ b/src/mscorlib/shared/System/StringComparer.cs @@ -179,15 +179,17 @@ namespace System 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) |