GlobalizationExtensions.cs 946 B

1234567891011121314151617181920212223242526272829303132
  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. using System;
  5. using System.Diagnostics;
  6. namespace System.Globalization
  7. {
  8. public static class GlobalizationExtensions
  9. {
  10. public static StringComparer GetStringComparer(this CompareInfo compareInfo, CompareOptions options)
  11. {
  12. if (compareInfo == null)
  13. {
  14. throw new ArgumentNullException(nameof(compareInfo));
  15. }
  16. if (options == CompareOptions.Ordinal)
  17. {
  18. return StringComparer.Ordinal;
  19. }
  20. if (options == CompareOptions.OrdinalIgnoreCase)
  21. {
  22. return StringComparer.OrdinalIgnoreCase;
  23. }
  24. return new CultureAwareComparer(compareInfo, options);
  25. }
  26. }
  27. }