| | | 1 | | // ----------------------------------------------------------------------- |
| | | 2 | | // <copyright file="EnumDisplayTextStrategy.cs" company="Stéphane ANDRE"> |
| | | 3 | | // Copyright (c) Stéphane ANDRE. All rights reserved. |
| | | 4 | | // </copyright> |
| | | 5 | | // ----------------------------------------------------------------------- |
| | | 6 | | |
| | | 7 | | using System; |
| | | 8 | | using System.ComponentModel.DataAnnotations; |
| | | 9 | | using System.Globalization; |
| | | 10 | | using MyNet.Globalization.Localization.Translation; |
| | | 11 | | using MyNet.Globalization.Localization.Translation.KeyGeneration; |
| | | 12 | | using MyNet.Reflection; |
| | | 13 | | |
| | | 14 | | namespace MyNet.Humanizer.Display.Strategies; |
| | | 15 | | |
| | | 16 | | /// <summary> |
| | | 17 | | /// Provides display names for enum values, using DisplayAttribute, DescriptionAttribute, or translation resources as ne |
| | | 18 | | /// </summary> |
| | | 19 | | /// <param name="translationService">The translation service to use for translating resource keys.</param> |
| | | 20 | | /// <param name="keyProvider">The key provider to use for generating translation keys.</param> |
| | 17 | 21 | | public sealed class EnumDisplayTextStrategy(ITranslationService translationService, ITranslationKeyProvider keyProvider) |
| | | 22 | | { |
| | | 23 | | /// <inheritdoc/> |
| | 0 | 24 | | protected override string? ProvideSymbol(Enum value, CultureInfo culture) => value.GetSymbol(); |
| | | 25 | | |
| | | 26 | | /// <inheritdoc/> |
| | | 27 | | protected override string? ProvideDisplayText(Enum value, CultureInfo culture) |
| | | 28 | | { |
| | 96 | 29 | | var displayAttribute = value.GetAttribute<DisplayAttribute>(); |
| | | 30 | | |
| | 96 | 31 | | return displayAttribute is not null ? ResolveDisplayAttribute(displayAttribute, culture) : null; |
| | | 32 | | } |
| | | 33 | | } |
| | | 34 | | |