Moved extensions.cs to shared folder in coreclr (#16459)
authorAnirudh Agnihotry <anirudhagnihotry098@gmail.com>
Wed, 21 Feb 2018 05:01:39 +0000 (21:01 -0800)
committerJan Kotas <jkotas@microsoft.com>
Wed, 21 Feb 2018 05:01:39 +0000 (21:01 -0800)
* Moved extensions.cs to shared folder

* added to shared to projItems

* Added new constructor

* Parameter Named Changed

src/mscorlib/shared/System.Private.CoreLib.Shared.projitems
src/mscorlib/shared/System/Globalization/GlobalizationExtensions.cs [new file with mode: 0644]
src/mscorlib/shared/System/StringComparer.cs

index 7e7fc28..d0dc439 100644 (file)
     <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 (file)
index 0000000..007283a
--- /dev/null
@@ -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);
+        }
+    }
+}
index b5f20c9..de311e9 100644 (file)
@@ -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)