| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="LocalizedSmartEnum.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System.Diagnostics.CodeAnalysis; |
| | | 8 | | using MyNet.Humanizer.Facade; |
| | | 9 | | using MyNet.Observable.Behaviors.Metadata.Features.Events; |
| | | 10 | | using MyNet.Observable.Metadata; |
| | | 11 | | using MyNet.Primitives; |
| | | 12 | | |
| | | 13 | | #pragma warning disable IDE0130 // Namespace does not match folder structure |
| | | 14 | | namespace MyNet.Observable; |
| | | 15 | | #pragma warning restore IDE0130 // Namespace does not match folder structure |
| | | 16 | | |
| | | 17 | | /// <summary> |
| | | 18 | | /// Culture-bound display text for a <see cref="ISmartEnum"/> value. |
| | | 19 | | /// </summary> |
| | | 20 | | /// <param name="enumValue">The smart enum value to present.</param> |
| | | 21 | | [SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix", Justification = "LocalizedSmartEnum is |
| | 9 | 22 | | public class LocalizedSmartEnum(ISmartEnum enumValue) : LocalizedSmartEnum<ISmartEnum>(enumValue); |
| | | 23 | | |
| | | 24 | | /// <summary> |
| | | 25 | | /// Culture-bound display text for a smart enum value. |
| | | 26 | | /// </summary> |
| | | 27 | | /// <typeparam name="TEnum">The smart enum type.</typeparam> |
| | | 28 | | /// <param name="enumValue">The smart enum value to present.</param> |
| | | 29 | | [ExemptFromGeneratedMetadata] |
| | | 30 | | [SuppressMessage("Naming", "CA1711:Identifiers should not have incorrect suffix", Justification = "LocalizedSmartEnum is |
| | | 31 | | public class LocalizedSmartEnum<TEnum>(TEnum enumValue) : CultureBoundValue<TEnum>(() => enumValue) |
| | | 32 | | where TEnum : ISmartEnum |
| | | 33 | | { |
| | | 34 | | /// <summary> |
| | | 35 | | /// Gets the localized display text for the smart enum value. |
| | | 36 | | /// </summary> |
| | | 37 | | public string Display => Value?.Humanize() ?? string.Empty; |
| | | 38 | | |
| | | 39 | | /// <inheritdoc /> |
| | | 40 | | public override string ToString() => Display; |
| | | 41 | | |
| | | 42 | | /// <inheritdoc /> |
| | | 43 | | public override void OnEvent(CultureChangedEvent e) |
| | | 44 | | { |
| | | 45 | | base.OnEvent(e); |
| | | 46 | | NotifyPropertyChanged(nameof(Display)); |
| | | 47 | | } |
| | | 48 | | |
| | | 49 | | /// <inheritdoc /> |
| | | 50 | | public override bool Equals(object? obj) => obj is LocalizedSmartEnum<TEnum> result && (result.Value?.Equals(Value) |
| | | 51 | | |
| | | 52 | | /// <inheritdoc /> |
| | | 53 | | public override int GetHashCode() => Value?.GetHashCode() ?? 0; |
| | | 54 | | } |
| | | 55 | | |