GlobalizationExtensions.cs 905 B

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