| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="CultureInfoNameComparer.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System; |
| | | 8 | | using System.Collections.Generic; |
| | | 9 | | using System.Globalization; |
| | | 10 | | |
| | | 11 | | namespace MyNet.Primitives.Comparers; |
| | | 12 | | |
| | | 13 | | /// <summary> |
| | | 14 | | /// Compares <see cref="CultureInfo"/> instances using their culture name. |
| | | 15 | | /// </summary> |
| | | 16 | | public sealed class CultureInfoNameComparer : IEqualityComparer<CultureInfo> |
| | | 17 | | { |
| | | 18 | | /// <summary> |
| | | 19 | | /// Gets the singleton instance. |
| | | 20 | | /// </summary> |
| | 16 | 21 | | public static CultureInfoNameComparer Instance { get; } = new(); |
| | | 22 | | |
| | | 23 | | /// <inheritdoc /> |
| | 333 | 24 | | public bool Equals(CultureInfo? x, CultureInfo? y) => StringComparer.OrdinalIgnoreCase.Equals(x?.Name, y?.Name); |
| | | 25 | | |
| | | 26 | | /// <inheritdoc /> |
| | | 27 | | public int GetHashCode(CultureInfo obj) |
| | | 28 | | { |
| | 963 | 29 | | ArgumentNullException.ThrowIfNull(obj); |
| | | 30 | | |
| | 960 | 31 | | return StringComparer.OrdinalIgnoreCase.GetHashCode(obj.Name); |
| | | 32 | | } |
| | | 33 | | } |
| | | 34 | | |